Anthropic Python SDK with Redline

The Anthropic Python SDK posts to /v1/messages under a configurable base URL. Point it at Redline and pass your key as the bearer auth token.

base_url and auth_token

The SDK default base URL is https://api.anthropic.com and it appends /v1/messages, so set base_url to https://redline-gateway.pages.dev with no path. Pass the key as auth_token (sent as Authorization: Bearer), not api_key.

# pip install anthropic
from anthropic import Anthropic

client = Anthropic(
    base_url="https://redline-gateway.pages.dev",
    auth_token="rl-...",
)

msg = client.messages.create(
    model="deepseek/deepseek-chat-v3.1",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
print(msg.content[0].text)
One endpoint gap messages.count_tokens calls /v1/messages/count_tokens, which Redline does not implement. Avoid that helper; ordinary messages.create works.

Related guides