Anthropic SDK,运行在你自己的 GPU 上。
你的 Anthropic API 密钥留在 api_key 中;warden 密钥放在单独的标头中。
文字说明: Anthropic SDK 把请求发送给 LM Warden,base_url 设为 warden,X-LMWarden-Key 填写 warden 密钥。LM Warden 检查密钥,支持 Anthropic Messages,按密钥优先级为请求排队,并交给副本路由器。路由器让每个会话留在已持有其缓存的副本上(每块 GPU 一个模型副本)。另有一条单独的路径通往 api.anthropic.com:规则把其他 Claude 模型发往这里,使用你自己的 API 密钥。
- 协议
- Anthropic Messages
- 支持情况
- 完全支持
你的规则指定的 Claude 模型在这里运行;其他所有模型和 /v1 路径都以你自己的登录发往 Anthropic。仅本地模式不需要 Anthropic 账户:warden 密钥就是 api_key,模型填写已部署模型的名称。
要求
- 必须开启路由,并且至少有一条已启用的规则。
- 该密钥必须被允许转发到 Anthropic(即带有“May relay”标记)。
设置
在控制台中,Connect 会用你的 warden 地址、你的密钥和你选择的模型写入这些文件。下面以占位符展示这些文件。
Router:保留你的 Anthropic 密钥
base_url 是这个 warden;你的 Anthropic API 密钥留在 api_key 中,warden 密钥放在默认标头中。
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."}]}'仅本地
warden 密钥就是 api_key,模型填写已部署模型的名称。
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."}]}'官方文档:https://platform.claude.com/docs/en/api/sdks/python(查阅日期:2026-10-04)。