valite
Docs navigation

Docs/Integrations/Anthropic SDK

Anthropic SDK

Point the Messages API at /anthropic — your sk-ant key passes through, your vk_ key is picked out automatically.

Setup

import anthropic

client = anthropic.Anthropic(
    api_key="sk-ant-...",  # unchanged
    base_url="https://gateway.valite.ai/anthropic",
    default_headers={"x-valite-api-key": "vk_..."},
)

resp = client.messages.create(
    model="claude-sonnet-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)

One header, two keys

The Anthropic SDK sends its key on x-api-key — the same header valite watches for vk_ keys. The gateway disambiguates by prefix: a vk_ value is consumed as your valite key; anything else (your sk-ant-… key) passes through to Anthropic untouched. Sending both headers, as in the examples above, is the recommended setup.

Tip

If your client can only set a single key field, you can put the vk_ key in x-api-key itself and supply the Anthropic key via a proxy-level default — but the two-header form is simpler and works with the stock SDK.

Streaming and tools

Server-sent-event streaming, tool use, and extended thinking pass through unchanged. Token usage is read from Anthropic's own message_start and message_delta events, and input tokens are normalized to uncached counts so costs compare fairly across providers in your profile.