API reference

API reference · API

Create a message (Anthropic wire format)

POST/v1/messagesAPI keyNo key

The Anthropic messages format over the same catalog, keys, policies, credits, and metering. Authenticate with x-api-key or a bearer token. The monthly spend cap is checked as on the other wires (answered 429 rate_limit_error, the Anthropic word), the body is held to the same size cap, and the gateway's request headers ride this wire too: session grouping, all three cache layers, routing steering, the provider cache breakpoint, the comparable fallback and resumable streams. There is no models fallback array in the body; use x-antimatter-fallback: comparable, or a key's comparableFallback. Errors use the Anthropic envelope. With no key and x402 on, a 402 names the price; see GET /api/x402.

Request body

application/json, required

Request body fields
FieldTypeWhat it is
modelrequiredstringAt most 200 characters.
max_tokensrequiredintegerRequired on this endpoint, unlike the OpenAI one. At most 9007199254740991.
systemstring or array of AnthropicBlock
messagesrequiredarray of object
messages[].rolerequiredstringOne of "user", "assistant", "system".
messages[].contentrequiredstring or array of AnthropicBlock
streamboolean
temperaturenumberFrom 0 to 1.
top_pnumberFrom 0 to 1.
top_kintegerPassed through to the vendor. At most 500.
stop_sequencesarray of string
toolsarray of object
tools[].namerequiredstring
tool_choiceobjectauto, any, none, or a named tool.
tool_choice.typerequiredstring
metadataobject

Example

{
  "model": "antimatter/auto",
  "max_tokens": 0,
  "messages": [
    {
      "role": "user",
      "content": "Say hello in five words."
    }
  ]
}

Answer 200

An Anthropic message, or an Anthropic SSE stream.

Headers: x-antimatter-upstream, x-antimatter-request-id, x-request-id, x-antimatter-cost-micros, x-antimatter-adjusted, x-ratelimit-limit, x-ratelimit-remaining, x-ratelimit-reset, x-antimatter-model, x-antimatter-byok, x-antimatter-cache, x-antimatter-cache-prefix, x-antimatter-cache-similarity, x-antimatter-cache-cost-micros, x-antimatter-cache-note, x-antimatter-cache-control, x-antimatter-auto-cache, x-antimatter-hedge, x-antimatter-coalesced, x-antimatter-route, x-antimatter-route-warning, x-antimatter-fallback, x-antimatter-json, x-antimatter-compress, x-antimatter-pii-redacted, x-antimatter-pii-kinds, x-antimatter-memory, x-antimatter-overhead-ms, x-antimatter-stream-id

Fields of the 200 answer
FieldTypeWhat it is
idstring
type"message"
role"assistant"
modelstringThe id you requested. x-antimatter-model carries the id that answered.
contentarray of AnthropicBlock
stop_reasonstring or null
stop_sequencestring or null
usageobject
usage.input_tokensinteger
usage.output_tokensinteger

Errors

  • 400Anthropic shaped error.
  • 401Anthropic shaped error.
  • 402Anthropic shaped error.
  • 403Anthropic shaped error.
  • 404Anthropic shaped error.
  • 429Anthropic shaped error.
  • 499The client closed the connection before the response finished.
  • 502Anthropic shaped error.
  • 503Anthropic shaped error.
  • 504The upstream did not answer within the gateway's timeout (upstream_timeout).

Every error answers in one shape, with its type, code and the field it names. The whole list is in the docs' Errors section.

Request headers it reads (12)
Request headers
FieldTypeWhat it is
x-antimatter-sessionstringA free form label that groups requests in the log. Printable ASCII, trimmed to 120 characters. At most 120 characters.
x-antimatter-cachestringSend on to opt into the exact match and prefix cache layers, or semantic to add the similarity layer on a key that enabled it. Non streaming only, never for a request served on your own provider key, and always scoped to your account. The response echoes x-antimatter-cache: hit, semantic, or miss. A hit costs nothing and spends no credits. One of "on", "semantic", "off".
x-antimatter-routestringA JSON object steering one autopilot decision. Every field is optional: policy (balanced, cheap, fast, quality), weights (price, latency, quality), max_price_per_1m, min_context, modality, require_tools, require_json. It shapes the routing of an antimatter/auto id only; a request that named a model is dispatched to that model and the directive is reported back in x-antimatter-route-warning as ignored rather than applied quietly. Anything unreadable in the object is reported the same way. At most 2000 characters.
x-antimatter-cache-controlstringSend auto to let the gateway place one provider side cache_control breakpoint at the boundary of a thread prefix a chain hash has proved unchanged. It does nothing when you placed your own markers, when the thread is not a verified continuation, or on a model whose wire does not read cache_control. The response says which in x-antimatter-cache-control. One of "auto".
x-antimatter-auto-cachestringAutomatic prompt caching for this request, over the key's autoCache policy and the deployment's default. On an Anthropic world the gateway marks a prompt start this account sent within five minutes (the system prompt and tools, or the conversation so far) so the vendor serves it from its cache; Gemini, OpenAI, DeepSeek and Grok cache by themselves. Cached tokens are billed at the world's cache read rate and written ones at its write rate; the hold stays the uncached worst case plus the write premium. One of "on", "off".
x-antimatter-hedgestring<ms>; max=<micros>, or off. When the first source has sent no byte in that many milliseconds (50 to 60000), the same request goes to a second source of the same world at the same card and the first answer wins; the other is cancelled and billed its prompt bound, which must fit under max or nothing is hedged. Never on your own provider key or under strict JSON. Over the key's hedgeMs and hedgeMaxMicros.
x-antimatter-resumablestringSend 1 on a streaming request made with a key to make the stream resumable. The answer carries x-antimatter-stream-id and numbers every SSE event with an id: line. If the connection drops, the generation carries on to its end and is billed in full, once, exactly as if you had stayed; pick it up at GET /v1/streams/{id}. The output is kept for ANTIMATTER_RESUME_TTL_S (600 s) after its last write, up to ANTIMATTER_RESUME_MAX_BYTES (4 MiB) of frames. Ignored on a request that does not stream, and on an x402 paid request, which has no key to resume with. One of "1".
x-antimatter-fallbackstringSend comparable to fall back, when the requested world and its models chain fail with a retriable error or every provider of it has an open breaker, to the nearest world priced at or below it on both sides with the capabilities and context this request needs, inside the key's allow and block lists. A request on your own provider key only falls back to a world that key serves. off turns off the key's own setting for this request. The answer names what happened in x-antimatter-fallback. One of "comparable", "off".
x-antimatter-jsonstringSend strict on a request whose response_format is json_object or json_schema to have the answer checked before it is handed over: it must parse, and for json_schema match the schema (format annotations are not checked). An answer that fails is asked for once more on the same world with a short repair note, then from the comparable fallback when one is set. Every attempt is billed as a live call and the hold covers two. A final failure is a 422 json_invalid carrying the last answer as error.content. On a stream the answer is asked for whole and checked first, so the first byte waits for the check; the checked answer then streams as chunks. off turns off the key's strictJson policy for this request. One of "strict", "off".
x-antimatter-compressstringPrompt compression, off unless asked for. safe: a document or tool result repeated later in the thread is sent once and each later copy becomes a short reference to the first; trailing spaces and blank line runs in long pasted blocks are tidied outside code fences; a long system prompt goes first in the system block; and on a world that reads cache_control, breakpoints mark the end of the stable prefix. aggressive: safe, and the turns before the last few are replaced by a summary from the cheapest paid model the key may use (or model=<id>; keep=<n> moves the cut), a request of its own, metered and billed. A short thread is not summarized, nor the last user turn or a tool call still waiting on its result. off turns off the key's compress policy for this request.
x-antimatter-memorystringLong term memory, where the operator has it on: a memory space id, or default for the key's own. The memories nearest the last user turn, of the request's end user (user on chat completions, metadata.user_id on /v1/messages, user or else safety_identifier on /v1/responses), go in front of the model in the wire's own system field: one system message after the caller's own on chat completions, a paragraph at the end of system on /v1/messages, a paragraph at the end of instructions on /v1/responses (the answer still echoes the instructions as sent). The recall is one embeddings request billed as the key, which needs the embeddings scope.
x-antimatter-memory-writestring1: after the answer, the conversation and the answer's text are queued for extraction into the space named by x-antimatter-memory (or the default), read and billed as the key like POST /v1/memories. On chat completions, /v1/messages and /v1/responses; a stream is read as it passes. One of "1".
Antimatter