Anthropic Messages
Configure Messages headers, output limits, and message content, then read text blocks.
Send a request
Choose a model and line supporting Messages and set the key from the API overview. This compatible example uses the 2023-06-01 version header and an illustrative output limit.
curl --fail-with-body 'https://gateway.irouter.io/v1/messages' \
-H "x-api-key: $IROUTER_API_KEY" \
-H 'anthropic-version: 2023-06-01' \
-H 'Content-Type: application/json' \
--data '{"model":"<model-id>","max_tokens":256,"messages":[{"role":"user","content":"Reply with a short greeting."}]}'Fields and response
The basic request needs model, messages, and max_tokens. Put system instructions in top-level system, rather than copying a Chat Completions system message.
Response content is a block array. Read text from blocks of type text and preserve other block types for their appropriate handlers. Inspect stop_reason for completion, output limits, or tool requests. Input and output counts in usage aid diagnostics; verify settled charges in the console.
SDK address and capability boundaries
Raw HTTP uses /v1/messages, but Anthropic SDKs take https://gateway.irouter.io and append the path. See the Anthropic SDK guide.
The gateway version covered here does not expose /v1/messages/count_tokens. Do not require it as a connection preflight. Tools, images, extended thinking, and specific version headers require model and line support. New fields in official APIs do not automatically establish iRouter support.
Field reference: Anthropic Messages.