tokrouterdocs
SDKs and frameworks

Anthropic SDK

Point the Anthropic Python / TypeScript SDK at TokRouter — base_url is the gateway origin, the SDK appends /v1/messages.

.mdOpen in Claude

The Anthropic SDK's base_url is an origin (no /v1); the SDK appends /v1/messages itself.

Python

import os
import anthropic

client = anthropic.Anthropic(
    api_key=os.environ["TOKROUTER_API_KEY"],
    base_url="https://api.tokrouter.dev",
)

with client.messages.stream(
    model="claude-opus-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Explain tool use in one sentence"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

TypeScript

import Anthropic from '@anthropic-ai/sdk'

const client = new Anthropic({
  apiKey: process.env.TOKROUTER_API_KEY!,
  baseURL: 'https://api.tokrouter.dev',
})

const msg = await client.messages.create({
  model: 'claude-sonnet-5',
  max_tokens: 512,
  messages: [{ role: 'user', content: 'Hello' }],
})

Call other vendors with the Anthropic SDK

Pass any catalog model id as model, e.g. gpt-5.4 or deepseek-v4-pro. The inbound protocol is Anthropic; the gateway maps it onto the target vendor.

Details: Anthropic protocol.