Skip to main content
This guide shows you how to point the official Anthropic SDK at the to11 gateway. Set the base_url to your gateway’s /v1 endpoint and use the Anthropic messages API as usual.

Python

pip install anthropic
import anthropic

client = anthropic.Anthropic(
    base_url="https://gw.to11.ai/v1",
    api_key="<your Anthropic API key>",  # provider credential, forwarded upstream
    default_headers={
        "x-to11-authorization": "Bearer <your to11 API key>",  # to11 auth — Settings → API keys
        "x-to11-project-id": "<your project id>",
    },
)

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=256,
    messages=[{"role": "user", "content": "Hello from to11!"}],
)
print(message.content[0].text)

TypeScript / Node.js

npm install @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: "https://gw.to11.ai/v1",
  apiKey: "<your Anthropic API key>", // provider credential, forwarded upstream
  defaultHeaders: {
    "x-to11-authorization": "Bearer <your to11 API key>", // to11 auth — Settings → API keys
    "x-to11-project-id": "<your project id>",
  },
});

const message = await client.messages.create({
  model: "claude-sonnet-4-6",
  max_tokens: 256,
  messages: [{ role: "user", content: "Hello from to11!" }],
});
console.log(message.content[0].text);

Streaming

with client.messages.stream(
    model="claude-sonnet-4-6",
    max_tokens=256,
    messages=[{"role": "user", "content": "Count to 10"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
Streamed responses are traced just like non-streaming calls — the gateway captures the same span and token counts either way.

System messages

Pass a top-level system parameter as you normally would:
message = client.messages.create(
    model="claude-sonnet-4-6",
    system="You are a helpful assistant that speaks only in haiku.",
    max_tokens=256,
    messages=[{"role": "user", "content": "Tell me about the ocean"}],
)

Tool use

Tool definitions follow the Anthropic input_schema format:
message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=256,
    messages=[{"role": "user", "content": "What's the weather in Paris?"}],
    tools=[{
        "name": "get_weather",
        "description": "Get current weather for a location",
        "input_schema": {
            "type": "object",
            "properties": {
                "location": {"type": "string"}
            },
            "required": ["location"],
        },
    }],
)

Extended thinking

Extended thinking blocks are preserved in Anthropic-format responses when enabled on the model. The thinking content type passes through the gateway as-is.

Cross-format routing

If you route an Anthropic-format request to an OpenAI model, the gateway translates automatically:
# Anthropic SDK format, but targeting an OpenAI model
message = client.messages.create(
    model="gpt-4o",
    max_tokens=256,
    messages=[{"role": "user", "content": "Hello!"}],
)
The system parameter is converted to a {"role": "system"} message, and tool definitions are translated to OpenAI’s parameters format.