Integrations
Anthropic SDK (Python & TypeScript)
Use the native Anthropic /v1/messages API and the official anthropic SDKs against ToRouter.
ToRouter exposes the native Anthropic Messages API at https://portal.torouter.ai/v1/messages. The official anthropic Python package and @anthropic-ai/sdk work unchanged — set the base URL and key, then call Claude (or any other model in the catalog) with client.messages.create(...).
Configuration
| Field | Value |
|---|---|
| Base URL | https://portal.torouter.ai (the SDK appends /v1/messages) |
| API key | sk-*** |
| Model | claude-opus-4-7, claude-sonnet-4-5, claude-haiku-4-5, ... |
Environment variables ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY are auto-detected.
Code
from anthropic import Anthropic
client = Anthropic(
base_url="https://portal.torouter.ai",
api_key="sk-***",
)
msg = client.messages.create(
model="claude-opus-4-7",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(msg.content[0].text)import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
baseURL: 'https://portal.torouter.ai',
apiKey: 'sk-***',
});
const msg = await client.messages.create({
model: 'claude-opus-4-7',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello' }],
});
console.log(msg.content[0].type === 'text' ? msg.content[0].text : '');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": 1024,
"messages": [{"role":"user","content":"Hello"}]
}'Prompt caching passes through
cache_control blocks on system / user content are forwarded to upstream Anthropic and Anthropic-on-OpenRouter accounts unchanged. ToRouter does not strip the field, so token savings show up directly in your usage dashboard.
Gotchas
- Use
https://portal.torouter.ai(no/v1) — the SDK appends/v1/messagesitself. Setting the full path produces/v1/v1/messagesand 404s. - Auth header is
x-api-key, notAuthorization: Bearer(the SDK handles this; only relevant for raw HTTP). - The OpenAI-style
/v1/chat/completionspath also accepts Claude models if you prefer the OpenAI protocol — see openai-python.