OpenAI-compatible API
Use the OpenAI SDK with ToRouter for chat completions, responses, embeddings and image generation.
ToRouter speaks native OpenAI on every endpoint your SDK uses. Change base_url and the key — your code is otherwise untouched.
Endpoints
| Method | Path | Purpose |
|---|---|---|
POST | /v1/chat/completions | Chat (OpenAI / Anthropic / Gemini / OpenRouter upstreams) |
POST | /v1/responses | Responses API (reasoning, tool use, multi-turn state) |
POST | /v1/embeddings | Text embeddings |
POST | /v1/images/generations | Text → image |
POST | /v1/images/edits | Image editing (multipart) |
GET | /v1/models | List available models |
Tool/function calling, JSON mode, response_format, tool_choice and structured outputs are passed through unchanged.
Python SDK
from openai import OpenAI
client = OpenAI(
api_key="sk-***",
base_url="https://portal.torouter.ai/v1",
)
resp = client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": "Write a haiku about routers."}],
)
print(resp.choices[0].message.content)The same client works for client.embeddings.create(...), client.images.generate(...) and client.responses.create(...).
curl
curl https://portal.torouter.ai/v1/embeddings \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{"model":"openai/text-embedding-3-small","input":"hello world"}'Embeddings require an API key on an OpenAI or OpenRouter group. Use the full model id from the model catalog (e.g. openai/text-embedding-3-small on OpenRouter). The gateway also accepts /api/v1/embeddings.
The OpenAI compat layer also fronts Anthropic and Gemini upstreams — if your group is on a Claude or Gemini account, gpt-5 style models get auto-translated. See Model identifiers.
Next steps
Base URL & authentication
Endpoint table for the ToRouter gateway — OpenAI, Anthropic and Gemini protocols, with both /v1 and /api/v1 mount points.
Anthropic-compatible API
Use the native Anthropic SDK against ToRouter — /v1/messages, count_tokens, prompt caching and anthropic-beta headers all pass through.