Skip to content

Anthropic API through the gateway

Code written for Anthropic's API keeps its shape. Point it at the gateway and every call is governed, recorded in Request logs and charged to the right team, and /v1/messages can answer from OpenAI, Gemini, Vertex AI and Bedrock models as well as Claude, in the Anthropic shape your code already reads.

What it is

The pages in this group describe each Anthropic endpoint as the gateway serves it: the paths the Anthropic SDKs call (anthropic for Python, @anthropic-ai/sdk for TypeScript), with Python, TypeScript and curl samples. To set up the SDK itself, start with Anthropic SDK for Python or Anthropic SDK for TypeScript.

The two settings

Setting Environment variable Python TypeScript Value
Base address ANTHROPIC_BASE_URL base_url baseURL https://<your-gateway> (the SDK adds /v1/messages)
Key ANTHROPIC_API_KEY api_key apiKey Your Vidai key (starts vk_), never a provider's key

The SDK sends the key in the x-api-key header, which the gateway accepts. The address and the main paths are under Connect your app on the Keys page and in System › Settings › Gateway; you get the key from Keys › Issue a key (its secret is shown once).

What goes through the gateway

Endpoint Page Reaches
POST /v1/messages Messages Anthropic, Bedrock (Claude), Vertex AI (Claude) as sent; OpenAI, Azure OpenAI, Gemini, Vertex AI (Gemini) and Bedrock's other models translated
POST /v1/messages/count_tokens Count tokens Anthropic; for another provider's model the gateway counts itself
/v1/files and /v1/files/{id} Files An Anthropic provider only
/v1/messages/batches Message batches Not through the gateway
GET /v1/models Model names Answered by the gateway: the models your key may call

Everything else in this group follows from one rule: messages are translated to any provider; files and tokens stay with Anthropic, except that a token count for another provider's model is answered by the gateway.

Errors

The gateway writes its own errors in Anthropic's shape, so the SDK raises its usual exceptions:

{"type":"error","error":{"type":"authentication_error","message":"…"}}

Match on the x-vidai-error-code response header, not the message: codes are stable and the same in every format. The full list is in Headers and errors.

Good to know

  • The gateway accepts Authorization: Bearer, x-api-key or x-goog-api-key. Two of them carrying different keys get a 401 (conflicting_auth_headers).
  • Cost is never in the answer: find the call in Request logs.