Anthropic SDK on your own GPUs.
Your Anthropic API key stays in api_key; the warden key rides in its own header.
In words: Anthropic SDK sends its requests to LM Warden with base_url set to the warden and X-LMWarden-Key holding a warden key. LM Warden checks the key, speaks Anthropic Messages, queues the request by key priority and hands it to the replica router, which keeps each session on the replica that already holds its cache, one model copy per GPU. A separate path goes to api.anthropic.com: rules send other Claude models here, on your own API key.
- Protocol
- Anthropic Messages
- Support
- Full support
The Claude models your rules name run here; every other model and /v1 path goes to Anthropic on your own login. Local only needs no Anthropic account: the warden key is the api_key and the model is a served name.
Requirements
- Routing must be on, with at least one enabled rule.
- The key must be allowed to relay to Anthropic (May relay).
Setup
In the console, Connect writes these files with your warden’s address, your key and the model you picked. Here they are with placeholders.
Router: keep your Anthropic key
base_url is this warden; your Anthropic API key stays in api_key and the warden key goes in default headers.
import anthropic
# api_key is your own Anthropic key (ANTHROPIC_API_KEY), used for pass-through.
client = anthropic.Anthropic(
base_url="https://your-warden",
default_headers={"X-LMWarden-Key": "vw_YOUR_KEY"},
)
message = client.messages.create(
model="claude-haiku-4-5", # a model your rules serve here; others go to Anthropic
max_tokens=256,
messages=[{"role": "user", "content": "Reply with the single word OK."}],
)
print(message.content[0].text)import Anthropic from "@anthropic-ai/sdk";
// apiKey is your own Anthropic key (ANTHROPIC_API_KEY), used for pass-through.
const client = new Anthropic({
baseURL: "https://your-warden",
defaultHeaders: { "X-LMWarden-Key": "vw_YOUR_KEY" },
});
const message = await client.messages.create({
model: "claude-haiku-4-5", // a model your rules serve here; others go to Anthropic
max_tokens: 256,
messages: [{ role: "user", content: "Reply with the single word OK." }],
});
console.log(message.content);curl https://your-warden/v1/messages \
-H "X-LMWarden-Key: vw_YOUR_KEY" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "claude-haiku-4-5", "max_tokens": 256, "messages": [{"role": "user", "content": "Reply with the single word OK."}]}'Local only
The warden key is the api_key and the model is a served name.
import anthropic
client = anthropic.Anthropic(base_url="https://your-warden", api_key="vw_YOUR_KEY")
message = client.messages.create(
model="your-served-model-name",
max_tokens=256,
messages=[{"role": "user", "content": "Reply with the single word OK."}],
)
print(message.content[0].text)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ baseURL: "https://your-warden", apiKey: "vw_YOUR_KEY" });
const message = await client.messages.create({
model: "your-served-model-name",
max_tokens: 256,
messages: [{ role: "user", content: "Reply with the single word OK." }],
});
console.log(message.content);curl https://your-warden/v1/messages \
-H "x-api-key: vw_YOUR_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "your-served-model-name", "max_tokens": 256, "messages": [{"role": "user", "content": "Reply with the single word OK."}]}'Official documentation: https://platform.claude.com/docs/en/api/sdks/python (read 2026-10-04).