Skip to main content

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.

MethodPathSummary
POST/api/event_logging/batchAccept and drop coding tool telemetry
POST/v1/messagesCreate a message (Anthropic Messages format)
POST/v1/messages/count_tokensCount 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:

StatusDescriptionBody
200The batch was accepted and droppedapplication/json EventLoggingAck

Response fields (200):

FieldTypeRequiredDescription
status"ok"YesAlways 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:

NameInTypeRequiredDescription
x-spanway-routing-skipsheaderenum: "true"NoSend 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):

FieldTypeRequiredDescription
cache_controlobject or nullNoCache Control
compactionobject or nullNo
containerobject or nullNoContainer
context_managementobject or nullNoContext Management
inference_geostring or nullNoInference Geo
max_tokensinteger or nullNoMax Tokens
mcp_serversarray of object or nullNoMcp Servers
messagesarray of objectYesMessages
metadataobject or nullNoMetadata
modelstringYesModel
output_configobject or nullNo
output_formatobject or nullNo
reasoning_effortstring or nullNoReasoning Effort
safeguardsarray of object or nullNoSafeguards
spanway_metadataobjectNoSpanway Metadata
speedstring or nullNoSpeed
stop_sequencesarray of string or nullNoStop Sequences
streamboolean or nullNoStream
systemstring or array of any or nullNoSystem
temperaturenumber or nullNoTemperature
thinkingobject or nullNoThinking
tool_choiceobject or nullNoTool Choice
toolsarray of object or nullNoTools
top_kinteger or nullNoTop K
top_pnumber or nullNoTop 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:

StatusDescriptionBody
200The message in the Anthropic Messages shape, or a stream of Anthropic server-sent events.application/json object
400The 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
401No valid key was sent, or the key has expired or is blocked.application/json AnthropicError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json AnthropicError
404The 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
408The provider did not answer before the request timed out.application/json AnthropicError
413The 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. Docsapplication/json object
422A 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
429Too 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 errorapplication/json AnthropicError
500The 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
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json AnthropicError
503The 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. Docsapplication/json AnthropicError

Response fields (200):

FieldTypeRequiredDescription
contentarray of objectYesContent
idstringYesId
modelstringYesModel
role"assistant"YesRole
stop_reasonenum: "end_turn", "max_tokens", "stop_sequence", "tool_use", "refusal" or nullYesStop Reason
stop_sequencestring or nullYesStop Sequence
type"message"YesType
usageobjectYesAnthropicResponseUsageBlock

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):

FieldTypeRequiredDescription
cache_controlobject or nullNoCache Control
compactionobject or nullNo
containerobject or nullNoContainer
context_managementobject or nullNoContext Management
inference_geostring or nullNoInference Geo
max_tokensinteger or nullNoMax Tokens
mcp_serversarray of object or nullNoMcp Servers
messagesarray of objectYesMessages
metadataobject or nullNoMetadata
modelstringYesModel
output_configobject or nullNo
output_formatobject or nullNo
reasoning_effortstring or nullNoReasoning Effort
safeguardsarray of object or nullNoSafeguards
spanway_metadataobjectNoSpanway Metadata
speedstring or nullNoSpeed
stop_sequencesarray of string or nullNoStop Sequences
streamboolean or nullNoStream
systemstring or array of any or nullNoSystem
temperaturenumber or nullNoTemperature
thinkingobject or nullNoThinking
tool_choiceobject or nullNoTool Choice
toolsarray of object or nullNoTools
top_kinteger or nullNoTop K
top_pnumber or nullNoTop 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:

StatusDescriptionBody
200The number of input tokens the request would use.application/json object
400The 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
401No valid key was sent, or the key has expired or is blocked.application/json ProxyError
403The key is valid but may not use this model, route or feature. A guardrail block is a 400, not a 403.application/json ProxyError
404The 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
408The provider did not answer before the request timed out.application/json ProxyError
413The 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. Docsapplication/json object
422The 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 errorapplication/json ProxyError or HTTPValidationError
429Too 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 errorapplication/json ProxyError
500The 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
502The provider, or a proxy in front of it, answered with something that is not a valid response.application/json ProxyError
503The 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. Docsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
input_tokensintegerYesInput Tokens