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
| Method | Path | Purpose |
|---|---|---|
POST | /v1/messages | Send a message (streaming or non-streaming) |
POST | /v1/messages/count_tokens | Count tokens for a request |
GET | /v1/models | List available models |
Auth headers
Anthropic uses x-api-key, not Authorization: Bearer.
x-api-key: sk-***
anthropic-version: 2023-06-01anthropic-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
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.