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

Google Gen AI SDK (Gemini)

Call Gemini 2.5 and the rest of Google's Gen AI catalog through ToRouter's native /v1beta endpoint.

ToRouter exposes the native Gemini v1beta API at https://portal.torouter.ai/v1beta. The new google-genai SDK and the legacy google-generativeai package both work — only the base URL and API key change.

Configuration

FieldValue
Base URLhttps://portal.torouter.ai/v1beta
API keysk-***
Modelgemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite, ...

Authentication accepts either the query parameter ?key=sk-*** or the header x-goog-api-key: sk-***. The SDKs use the header form by default.

Code

from google import genai

client = genai.Client(
    api_key="sk-***",
    http_options={"base_url": "https://portal.torouter.ai"},
)

resp = client.models.generate_content(
    model="gemini-2.5-pro",
    contents="Hello",
)
print(resp.text)
import google.generativeai as genai

genai.configure(
    api_key="sk-***",
    client_options={"api_endpoint": "portal.torouter.ai"},
    transport="rest",
)

model = genai.GenerativeModel("gemini-2.5-pro")
print(model.generate_content("Hello").text)
curl "https://portal.torouter.ai/v1beta/models/gemini-2.5-pro:generateContent" \
  -H "x-goog-api-key: sk-***" \
  -H "Content-Type: application/json" \
  -d '{"contents":[{"parts":[{"text":"Hello"}]}]}'

Gotchas

  • The google-genai http_options.base_url value should be the host root (https://portal.torouter.ai) — the SDK appends /v1beta/.... The legacy SDK takes only the hostname via api_endpoint.
  • Streaming uses models.generate_content_stream(...) (new SDK) or stream=True (legacy). Both work over the same base URL.
  • Some Gemini-only features (Files API, embeddings on text-embedding-004, grounding) are pass-through; per-model availability depends on the channel your key resolves to.

Next steps

Create an API key

Base URL & auth reference

Model catalog

Troubleshoot errors

Anthropic SDK (Python & TypeScript)

Use the native Anthropic /v1/messages API and the official anthropic SDKs against ToRouter.

Cursor

Point Cursor's chat and Composer at ToRouter to use Claude, GPT, Gemini and more from one key.

Table of Contents

ConfigurationCodeNext steps