LogoToRouter Docs
LogoToRouter Docs
HomepageWhat is ToRouter5-minute quickstartCore concepts
OpenAI Python SDKOpenAI Node / TypeScript SDKAnthropic SDK (Python & TypeScript)Google Gen AI SDK (Gemini)CursorCline (VS Code extension)Claude Code CLILangChain & LlamaIndexDify & n8n (no-code)
Integrations

OpenAI Python SDK

Call GPT, Claude, Gemini and every other model in the catalog from the official openai Python package.

The official openai Python SDK works against ToRouter without changes — point base_url at the gateway, swap in your ToRouter key, and the OpenAI Chat Completions / Responses / Embeddings / Images APIs route to OpenAI, Anthropic, Google and every other upstream behind one endpoint.

Configuration

FieldValue
Base URLhttps://portal.torouter.ai/v1
API keysk-*** (create one at the ToRouter console)
Modelgpt-5, claude-opus-4-7, gemini-2.5-pro, ... (see the catalog)

Environment variables OPENAI_BASE_URL and OPENAI_API_KEY are picked up automatically if you prefer not to pass them in code.

Code

from openai import OpenAI

client = OpenAI(
    base_url="https://portal.torouter.ai/v1",
    api_key="sk-***",
)

resp = client.chat.completions.create(
    model="gpt-5",
    messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)
from openai import OpenAI

client = OpenAI(
    base_url="https://portal.torouter.ai/v1",
    api_key="sk-***",
)

stream = client.chat.completions.create(
    model="claude-opus-4-7",
    messages=[{"role": "user", "content": "Stream me a haiku"}],
    stream=True,
)
for chunk in stream:
    delta = chunk.choices[0].delta.content or ""
    print(delta, end="", flush=True)
curl https://portal.torouter.ai/v1/chat/completions \
  -H "Authorization: Bearer sk-***" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-5","messages":[{"role":"user","content":"Hello"}]}'

Gotchas

  • OPENAI_BASE_URL overrides the SDK default; if your shell already has it set to a different proxy, the constructor argument wins.
  • Do not append a trailing slash — use /v1, not /v1/. The SDK joins paths and a trailing slash silently produces 404s.
  • The Responses API is available on the same base URL (POST /v1/responses); the SDK's client.responses.create(...) works unchanged.

Next steps

Create an API key

Base URL & auth reference

Model catalog

Troubleshoot errors

Usage details & CSV export

Filter request logs by date and model, break down tokens, and export everything to CSV.

OpenAI Node / TypeScript SDK

Use the official openai npm package against ToRouter from Node, Bun, Deno or the browser.

Table of Contents

ConfigurationCodeNext steps