Create a message
/v1/messagesCreate a message.
Drop-in compatible with Anthropic's Messages API: the body is a Messages request and the answer a Messages response, in Anthropic's format. With an Anthropic or Claude on Vertex key the request goes to Claude as sent (apart from what the gateway sets: the model the key allows, guardrail redactions); with a key for another provider it is translated, and a field that provider cannot take is a 400 naming it. Server tools, mcp_servers and container are not supported (400).
Credentials, in this order: x-virtual-key; Authorization: Bearer vk-...; x-config (a routing config, with x-organization); x-api-key, which is what the Claude SDKs send from ANTHROPIC_API_KEY; any other Authorization: Bearer token. A value starting vk- is a virtual key's API key; anything else is the provider's own key (Anthropic, unless x-provider names another provider). No credential is a 401.
What the gateway adds is the same as on chat completions: the response cache (x-cache-mode), retries and fallbacks (x-retry-*, x-fallback-*), and guardrails (the virtual key's plus x-guardrail) on the input and the answer. The response carries x-cache-status, x-retry-count, x-fallback-provider (when a fallback answered), x-virtual-key-slug and x-guardrail-status (when guardrails apply). anthropic-beta is forwarded to Anthropic and Claude on Vertex.
Streaming. With stream: true the response is text/event-stream with Anthropic's events (message_start, content_block_start, content_block_delta, content_block_stop, message_delta, message_stop). A failure after the stream has started ends it with an error event.
Errors are in Anthropic's shape, {"type":"error","error":{"type":...,"message":...}}, so the SDK raises the matching exception: 400 for an invalid request, 401 for a missing or invalid credential, 403 when the virtual key is disabled, expired or out of credit or the model is not allowed, 422 when a guardrail blocks (with x-guardrail-status: BLOCK), 429 for a rate limit.
Authorization
AuthorizationBearer <slug>.<secret>A virtual key's API key (
vk-....<secret>), asAuthorization: Bearer. What the OpenAI SDK sends from itsapi_key. Used by the inference endpoints.- or
x-virtual-keyheaderA virtual key's API key in the
x-virtual-keyheader, for clients that keepAuthorizationfor something else. - or
x-api-keyheaderDirect credentials: the provider's own API key in
x-api-key, with the provider named inx-provider(for exampleopenai). On/v1/messagesa virtual key is accepted inx-api-keytoo, which is what the Claude SDK sends.
Headers
x-providerstringWith direct credentials: the provider
x-api-keybelongs to, for exampleopenaioranthropic(case and dashes are normalised). Not used with a virtual key.x-cache-modestringTurns on the response cache for this request:
simple(exact match) orsemantic(a similar earlier request). Without it nothing is read from or written to the cache. The outcome is in thex-cache-statusresponse header.x-cache-ttlinteger<int32>How long, in seconds, a response stored by this request stays in the cache. When the organization has a cache TTL set, this can shorten it but not extend it.
x-cache-force-refreshbooleantrueskips the cache lookup, calls the provider and replaces the stored response (x-cache-status: REFRESH).x-retry-countinteger<int32>How many times to retry a failed provider call, 0 to 5. Without the header, chat completions, Claude Messages and prompt completions do not retry, and the other endpoints retry up to 3 times. Retries back off exponentially from 1 second and honour a numeric
Retry-After. The number made is in thex-retry-countresponse header.x-retry-status-codesstringComma-separated provider status codes to retry on. Default
429,500,502,503,504,529.x-fallback-1-providerstringThe provider to try when the request fails after its retries. Up to five fallbacks, tried in order:
x-fallback-1-*tox-fallback-5-*. The provider that answered is in thex-fallback-providerresponse header.x-fallback-1-api-keystringThe API key for fallback 1's provider.
x-fallback-1-modelstringThe model fallback 1 uses. Optional: the request's own model otherwise.
x-guardrailstringA guardrail slug (
gr-...) to apply to this request, in addition to any the virtual key carries. A BLOCK is a 422 withx-guardrail-status: BLOCK.x-configstringA routing config slug: the config chooses the provider, model and key (load balancing, fallback or conditional routing). Without a virtual key, send
x-organizationwith it to name the config's organization.x-organizationstringThe organization slug. Required with
x-config; with a virtual key the key's organization is used.x-workspace-idstringWorkspace id (UUID) to attribute the request to in logs and analytics.
x-metadatastringA JSON object of your own string key/value pairs, stored with the request's log entry for filtering.
x-prompt-slugstringAttributes the request to a prompt from the prompt library, for its analytics.
x-prompt-versioninteger<int32>The prompt version the request used, with
x-prompt-slug.x-vertex-projectstringGoogle Vertex AI keys only: the GCP project to call, instead of the one stored with the key.
x-vertex-regionstringGoogle Vertex AI keys only: the region to call (or
global), instead of the one stored with the key.anthropic-betastringAnthropic beta features, comma-separated (for example
context-management-2025-06-27). Forwarded to Anthropic and Claude on Vertex only; at most 32 names of lower-case letters, digits and dashes.
Responses
The message. With stream: true, a stream of Anthropic Messages events.