Anthropic SDK を自分の GPU で。
Anthropic の API キーは api_key のまま。warden のキーは専用のヘッダーで送られます。
テキストによる説明: Anthropic SDK は、base_url に warden を、X-LMWarden-Key に warden のキーを設定して LM 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 時点)。