LogoToRouter Docs
LogoToRouter Docs
HomepageWhat is ToRouter5-minute quickstartCore concepts
Base URL & authenticationOpenAI-compatible APIAnthropic-compatible APIGemini-compatible APIStreaming responses (SSE)Model identifiers & vendor prefixesPlayground — test in the browser
Gateway

Anthropic-compatible API

Use the native Anthropic SDK against ToRouter — /v1/messages, count_tokens, prompt caching and anthropic-beta headers all pass through.

ToRouter exposes a native Anthropic surface at POST /v1/messages. The official anthropic SDK works unmodified — just change the base URL and key.

Endpoints

MethodPathPurpose
POST/v1/messagesSend a message (streaming or non-streaming)
POST/v1/messages/count_tokensCount tokens for a request
GET/v1/modelsList available models

Auth headers

Anthropic uses x-api-key, not Authorization: Bearer.

x-api-key: sk-***
anthropic-version: 2023-06-01

anthropic-beta headers (e.g. prompt-caching-2024-07-31, extended-cache-ttl-2025-04-11) and cache_control blocks on messages are passed through to the upstream.

Python SDK

example.py
from anthropic import Anthropic

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

msg = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Summarise CIDR notation in one sentence."}],
)
print(msg.content[0].text)

The SDK auto-appends /v1/messages, so base_url is the host root.

curl

curl https://portal.torouter.ai/v1/messages \
  -H "x-api-key: sk-***" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-4-7",
    "max_tokens": 256,
    "messages": [{"role":"user","content":"hi"}]
  }'

When your group's platform is OpenAI or OpenRouter, ToRouter transparently converts /v1/messages to OpenAI Chat Completions upstream. Your client sees standard Anthropic responses either way.

Next steps

Streaming responses

stream: true for SSE delta events.

Anthropic SDK integration

Full setup, including Claude Code.

Claude Code

Use ToRouter with Anthropic's CLI.

OpenAI-compatible API

Use the OpenAI SDK with ToRouter for chat completions, responses, embeddings and image generation.

Gemini-compatible API

Native Google Gemini /v1beta surface — generateContent, streamGenerateContent and the google-genai SDK.

Table of Contents

EndpointsAuth headersPython SDKcurlNext steps