Anthropic SDK migration
Point the Anthropic SDK or Claude Code at Stav. Claude models are proxied to Anthropic unchanged; every other catalogue model is translated, with reasoning carried across.
Stav serves the Anthropic Messages API at POST /v1/messages, plus POST /v1/messages/count_tokens.
Change two lines
import os
from anthropic import Anthropic
client = Anthropic(
api_key=os.environ["STAV_API_KEY"], # sk_stav_live_...
base_url="https://api.stav.ai", # no /v1 — the SDK adds it
)
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: process.env.STAV_API_KEY,
baseURL: "https://api.stav.ai",
});
A base URL ending in /v1 sends requests to /v1/v1/messages, which 404s.
Stav accepts the key as x-api-key (what the SDK sends) or Authorization: Bearer.
Model names
Use anthropic/claude-sonnet-4-5 or the bare claude-sonnet-4-5. Dated snapshots (claude-sonnet-4-5-20250929) and -latest names also resolve. auto, a Router (@acme/eu-only) and any other catalogue model work too.
Two paths, one endpoint
Claude models — proxied to Anthropic. The request goes to Anthropic's API as sent: thinking, cache_control, server tools, beta features and new fields all work. This applies when you name a Claude model and when auto or a Router selects one.
Every other model — translated to chat completions and dispatched like /v1/chat/completions.
| Feature | On a non-Claude model |
|---|---|
tools with input_schema, tool_choice, tool_result | Carried across |
| Images | Carried across; with auto or a Router, only vision-capable models are considered |
thinking | Translated to a reasoning_effort level |
cache_control | Left out, named in X-Stav-Dropped-Params |
Server tools (web_search_20250305, bash_20250124, …) | Left out, each type named in X-Stav-Dropped-Params (and tool_choice if it pointed at one) |
Leaving out cache_control costs money, not correctness, so the call still succeeds. If your workload depends on the prompt cache, use a Claude model and watch for that header.
A Claude model is not sovereign. It runs at Anthropic. For EU-hosted inference, use a non-Claude model or a Router with a sovereignty floor. See Sovereignty.
Extended thinking
msg = client.messages.create(
model="anthropic/claude-sonnet-4-5",
max_tokens=8192,
thinking={"type": "enabled", "budget_tokens": 4096},
messages=[{"role": "user", "content": "Plan a Postgres 14 → 17 migration."}],
)
for block in msg.content:
if block.type == "thinking":
print("[reasoning]", block.thinking)
On Claude models Anthropic validates budget_tokens (at least 1024, below max_tokens) and Stav returns its error as is. See Reasoning.
Prompt caching
msg = client.messages.create(
model="anthropic/claude-sonnet-4-5",
max_tokens=1024,
system=[{
"type": "text",
"text": LONG_SYSTEM_PROMPT,
"cache_control": {"type": "ephemeral"},
}],
messages=messages,
)
print(msg.usage.cache_read_input_tokens)
Counting tokens
count = client.messages.count_tokens(
model="anthropic/claude-sonnet-4-5",
system=LONG_SYSTEM_PROMPT,
tools=TOOLS,
messages=messages,
)
print(count.input_tokens)
Not billed. For Claude models Anthropic does the count. For other models it is a local estimate from the model's tokenizer.
Scopes
A key with no scopes can call everything. A scoped key needs inference:messages for both endpoints.
Claude Code
export ANTHROPIC_BASE_URL="https://api.stav.ai"
export ANTHROPIC_AUTH_TOKEN="sk_stav_live_..."
Claude Code then sends every turn to /v1/messages on Stav and it is charged to your Stav wallet. With a Claude model everything works as before. With a non-Claude model, tools, streaming and thinking work; cache_control is left out as described above.
Migration checklist
- Create a
sk_stav_test_key. - Set
base_urltohttps://api.stav.ai— without/v1. - Run your tests against a Claude model. They should pass unchanged.
- Try a non-Claude model or
auto, and checkX-Stav-Dropped-Params. - Set a sovereignty floor for the workspace.
- Roll out with a
sk_stav_live_key.
Not available
- Files API, Message Batches API, Models API on the Anthropic path. Use
GET /v1/modelswith an OpenAI-style client to list models. - Server tools and computer use on non-Claude models.