LogoToRouter Docs
LogoToRouter Docs
HomepageWhat is ToRouter5-minute quickstartCore concepts
OpenAI Python SDKOpenAI Node / TypeScript SDKAnthropic SDK (Python & TypeScript)Google Gen AI SDK (Gemini)CursorCline (VS Code extension)Claude Code CLILangChain & LlamaIndexDify & n8n (no-code)
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

FieldValue
Base URLhttps://portal.torouter.ai (the SDK appends /v1/messages)
API keysk-***
Modelclaude-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/messages itself. Setting the full path produces /v1/v1/messages and 404s.
  • Auth header is x-api-key, not Authorization: Bearer (the SDK handles this; only relevant for raw HTTP).
  • The OpenAI-style /v1/chat/completions path also accepts Claude models if you prefer the OpenAI protocol — see openai-python.

Next steps

Create an API key

Base URL & auth reference

Model catalog

Troubleshoot errors

OpenAI Node / TypeScript SDK

Use the official openai npm package against ToRouter from Node, Bun, Deno or the browser.

Google Gen AI SDK (Gemini)

Call Gemini 2.5 and the rest of Google's Gen AI catalog through ToRouter's native /v1beta endpoint.

Table of Contents

ConfigurationCodeNext steps