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
| Field | Value |
|---|---|
| Base URL | https://portal.torouter.ai/v1beta |
| API key | sk-*** |
| Model | gemini-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-genaihttp_options.base_urlvalue should be the host root (https://portal.torouter.ai) — the SDK appends/v1beta/.... The legacy SDK takes only the hostname viaapi_endpoint. - Streaming uses
models.generate_content_stream(...)(new SDK) orstream=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.