Anthropic pass-through
The /anthropic route forwards any Anthropic API path, such as /v1/messages, /v1/messages/count_tokens, /v1/messages/batches or /v1/models, to Anthropic unchanged. Teams keep the Anthropic SDK and every Anthropic feature exactly as Anthropic exposes it, while the gateway holds the Anthropic key, checks the virtual key and records the spend. When the model in the body names a deployment from model_list, the gateway routes through that deployment, so its retries and fallbacks apply.
A real-world scenario
A coding assistant team uses the Anthropic Message Batches API to grade pull requests overnight. The unified API does not cover batches, and the team does not want an Anthropic key on the batch runner. They point the Anthropic SDK at https://gateway.example.com/anthropic and pass a virtual key as the API key. The batches run as before, and finance sees the cost per team the next morning.
Before you start
The gateway needs an Anthropic credential. It looks first for a model_list deployment of provider Anthropic with use_in_pass_through: true, then for the environment variable below.
| Variable | Purpose |
|---|---|
ANTHROPIC_API_KEY | The Anthropic key the gateway sends upstream. |
ANTHROPIC_API_BASE | Optional. Changes the upstream address from https://api.anthropic.com. |
Steps
-
Give the gateway the credential. Open
/ui/models-and-endpoints, on the Add Model tab pick Anthropic under Provider, pick a model, open Advanced Settings, turn on Use in pass through routes and click Add Model. Or setANTHROPIC_API_KEYand restart the gateway. -
Issue a virtual key on
/ui/api-keyswith + Create New Key, then Create Key. -
Call Anthropic through the gateway. Put the virtual key in
x-api-key, where the Anthropic SDK puts its own key.curl -X POST http://localhost:4000/anthropic/v1/messages \-H "x-api-key: $SPANWAY_API_KEY" \-H "anthropic-version: 2023-06-01" \-H "Content-Type: application/json" \-d '{"model": "claude-sonnet-5-5", "max_tokens": 256, "messages": [{"role": "user", "content": "Summarise this ticket in one sentence."}]}' -
With the Anthropic SDK, set the base URL to
http://localhost:4000/anthropicand the API key to the virtual key. -
Open
/ui/logsand click the newest row to see the request, the key and its cost.
Expected result
Anthropic's own response, with Anthropic's status code and headers. Streaming is streamed through as it arrives.
{
"id": "msg_01Xf",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-5-5",
"content": [{"type": "text", "text": "The customer wants one of two duplicate charges refunded."}],
"stop_reason": "end_turn",
"usage": {"input_tokens": 18, "output_tokens": 12}
}
The spend log row carries the calling key, team and user, and the cost worked out from usage. Budgets, rate limits and blocked keys apply as on the unified endpoints. Skills uploaded through this route are checked by skill scanning first, like uploads to POST /v1/skills.
Errors
| Status | Message | What it means and how to fix it |
|---|---|---|
401 | Authentication Error, Invalid proxy server token passed | The virtual key in x-api-key is missing, wrong, expired or blocked. |
403 | Key/team denied access to passthrough route /anthropic/... | The key or team lists the route in denied_passthrough_routes. The message goes on with Matched <pattern> in denied_passthrough_routes, naming the pattern to remove from the key or team. |
401 | No Anthropic credential is configured on this proxy and the request carried no upstream Anthropic credential. | The gateway has no Anthropic key and the caller sent none, so the call never reaches Anthropic. The Spanway virtual key is never forwarded. Add a deployment with Use in pass through routes on, set ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN, or send your own Anthropic key in x-api-key. |
400 | skill_scan_blocked or skill_scan_incomplete in error.type | A skill or new skill version sent to /anthropic/v1/skills or /anthropic/v1/skills/{skill_id}/versions was refused by skill scanning before it reached Anthropic. Remove what the message names. |
400 | skill_scan_unsupported in error.type | Any other change to skills through this route, or a skill sent as JSON instead of multipart form data, is refused so no skill reaches Anthropic unscanned. Use POST /v1/skills, or send multipart form data to one of the two paths above. |
401 from Anthropic | invalid x-api-key | Anthropic refused the key the gateway sent. Replace the Anthropic key on the deployment or in ANTHROPIC_API_KEY. |
| Any other | Anthropic's own error body | Anthropic refused the request. The message is returned unchanged. |
Related
Pass-through endpoints lists every built-in route. The unified Anthropic Messages endpoint and count tokens work with every provider and run guardrails automatically. The Anthropic provider page covers Anthropic through the unified endpoints.