Anthropic passthrough API
This page documents the 3 gateway endpoints tagged anthropic_passthrough in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.
| Method | Path | Summary |
|---|---|---|
| POST | /api/event_logging/batch | Accept and drop coding tool telemetry |
| POST | /v1/messages | Create a message (Anthropic Messages format) |
| POST | /v1/messages/count_tokens | Count the tokens of an Anthropic Messages request |
Endpoints
POST /api/event_logging/batch
Accept and drop coding tool telemetry
Claude Code sends usage telemetry to this path when its base URL points at the gateway. The gateway answers ok and throws the events away, so the tool does not log 404 errors and no telemetry is stored or forwarded. Anyone may call it, no key is needed and nothing changes.
Request body (application/json, object):
Example request:
curl -X POST "http://localhost:4000/api/event_logging/batch" \
-H "Content-Type: application/json" \
-d '{
"events": [
{
"event_data": {
"event_name": "session_start"
},
"event_type": "ClientEvent"
}
]
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The batch was accepted and dropped | application/json EventLoggingAck |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
status | "ok" | Yes | Always ok, the events are accepted and dropped |
POST /v1/messages
Create a message (Anthropic Messages format)
Send a request in the Anthropic Messages format to any model the gateway knows, not only Anthropic models. The gateway translates the request for the model's provider and answers in the Messages format. Docs
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
x-spanway-routing-skips | header | enum: "true" | No | Send true to get the candidates the router skipped in the answer headers. See https://docs.spanway.ai/docs/proxy/routing_headers |
Request body (application/json, object):
| Field | Type | Required | Description |
|---|---|---|---|
cache_control | object or null | No | Cache Control |
compaction | object or null | No | |
container | object or null | No | Container |
context_management | object or null | No | Context Management |
inference_geo | string or null | No | Inference Geo |
max_tokens | integer or null | No | Max Tokens |
mcp_servers | array of object or null | No | Mcp Servers |
messages | array of object | Yes | Messages |
metadata | object or null | No | Metadata |
model | string | Yes | Model |
output_config | object or null | No | |
output_format | object or null | No | |
reasoning_effort | string or null | No | Reasoning Effort |
safeguards | array of object or null | No | Safeguards |
spanway_metadata | object | No | Spanway Metadata |
speed | string or null | No | Speed |
stop_sequences | array of string or null | No | Stop Sequences |
stream | boolean or null | No | Stream |
system | string or array of any or null | No | System |
temperature | number or null | No | Temperature |
thinking | object or null | No | Thinking |
tool_choice | object or null | No | Tool Choice |
tools | array of object or null | No | Tools |
top_k | integer or null | No | Top K |
top_p | number or null | No | Top P |
Example request:
curl -X POST "http://localhost:4000/v1/messages" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"max_tokens": 512,
"messages": [
{
"content": "Review this function for bugs: def add(a, b): return a - b",
"role": "user"
}
],
"model": "claude-sonnet-5-5",
"system": "You are a careful reviewer."
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The message in the Anthropic Messages shape, or a stream of Anthropic server-sent events. | application/json object |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json AnthropicError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json AnthropicError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json AnthropicError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json AnthropicError |
| 408 | The provider did not answer before the request timed out. | application/json AnthropicError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | A budget (key, user, team, organization or end user) is used up. The status is spanway_settings.budget_exceeded_status_code, 422 by default. Like every error on this route it comes back in the Anthropic envelope, here with error.type api_error. | application/json AnthropicError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json AnthropicError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json AnthropicError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json AnthropicError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json AnthropicError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
content | array of object | Yes | Content |
id | string | Yes | Id |
model | string | Yes | Model |
role | "assistant" | Yes | Role |
stop_reason | enum: "end_turn", "max_tokens", "stop_sequence", "tool_use", "refusal" or null | Yes | Stop Reason |
stop_sequence | string or null | Yes | Stop Sequence |
type | "message" | Yes | Type |
usage | object | Yes | AnthropicResponseUsageBlock |
POST /v1/messages/count_tokens
Count the tokens of an Anthropic Messages request
Count tokens for Anthropic Messages API format.
This endpoint follows the Anthropic Messages API token counting specification. It accepts the same parameters as the /v1/messages endpoint but returns token counts instead of generating a response.
Example usage:
curl -X POST "http://localhost:4000/v1/messages/count_tokens?beta=true" -H "Content-Type: application/json" -H "Authorization: Bearer your-key" -d '{
"model": "claude-3-sonnet-20240229",
"messages": [{"role": "user", "content": "Hello Claude!"}]
}'
The response is {"input_tokens": <number>}.
Request body (application/json, object):
| Field | Type | Required | Description |
|---|---|---|---|
cache_control | object or null | No | Cache Control |
compaction | object or null | No | |
container | object or null | No | Container |
context_management | object or null | No | Context Management |
inference_geo | string or null | No | Inference Geo |
max_tokens | integer or null | No | Max Tokens |
mcp_servers | array of object or null | No | Mcp Servers |
messages | array of object | Yes | Messages |
metadata | object or null | No | Metadata |
model | string | Yes | Model |
output_config | object or null | No | |
output_format | object or null | No | |
reasoning_effort | string or null | No | Reasoning Effort |
safeguards | array of object or null | No | Safeguards |
spanway_metadata | object | No | Spanway Metadata |
speed | string or null | No | Speed |
stop_sequences | array of string or null | No | Stop Sequences |
stream | boolean or null | No | Stream |
system | string or array of any or null | No | System |
temperature | number or null | No | Temperature |
thinking | object or null | No | Thinking |
tool_choice | object or null | No | Tool Choice |
tools | array of object or null | No | Tools |
top_k | integer or null | No | Top K |
top_p | number or null | No | Top P |
Example request:
curl -X POST "http://localhost:4000/v1/messages/count_tokens" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"content": "Review this function for bugs: def add(a, b): return a - b",
"role": "user"
}
],
"model": "claude-sonnet-5-5",
"system": "You are a careful reviewer."
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The number of input tokens the request would use. | application/json object |
| 400 | The request is invalid, for example a missing or unsupported parameter, a prompt longer than the model's context window, content a guardrail or the provider refused, or no deployment that satisfies the data policy of the key, team or organization (No deployment of model 'gpt-5.5' satisfies the data policy: ...). error.message says which. | application/json ProxyError |
| 401 | No valid key was sent, or the key has expired or is blocked. | application/json ProxyError |
| 403 | The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403. | application/json ProxyError |
| 404 | The route or resource does not exist, or this key cannot see it. An unknown model name is a 400 (Invalid model name passed in model=...). | application/json ProxyError |
| 408 | The provider did not answer before the request timed out. | application/json ProxyError |
| 413 | The request body is larger than max_request_size_mb (100 MB by default), or an upload is larger than its own limit. The gateway refused it before reading the key. Docs | application/json object |
| 422 | The request body does not have the expected shape, or a budget (key, user, team, organization or end user) is used up: error.type is budget_exceeded. The budget status is spanway_settings.budget_exceeded_status_code, 422 by default. With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError or HTTPValidationError |
| 429 | Too many requests. A provider limit or a gateway limit (requests or tokens per minute, or parallel requests) refused the call, and error.type says which. A gateway limit also sends the RateLimit headers and x-spanway-rate-limited-by. Docs With access requests licensed, a key or team limit refusal also carries error.request_increase, which names the access request to file for a higher limit. Ask from an error | application/json ProxyError |
| 500 | The gateway or the provider failed unexpectedly, or the gateway could not reach the provider. Retry, and quote the request id if it keeps failing. | application/json ProxyError |
| 502 | The provider, or a proxy in front of it, answered with something that is not a valid response. | application/json ProxyError |
| 503 | The provider is overloaded or unavailable. With Redis rate limiting, a 503 also means the gateway could not check the rate limit counters and refused the request, because fail_closed_rate_limit_enforcement is on. Docs | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
input_tokens | integer | Yes | Input Tokens |