Skip to content
alpharouter

Docs

Messages API

Accepts the Anthropic-native shape directly. Code written against the Claude SDK only needs its base_url changed.

Request shape

system is a top-level field and max_tokens is required. Those two points differ from Chat Completions.

FieldTypeRequiredNote
modelstringYesModel ID or route path
messagesarrayYesuser, assistant
systemstringNoTop-level field
max_tokensintegerYesRequired on this path

Routing behavior

Routing paths work here too, but candidates are limited to models that support the Messages shape.

Content blocks

The response content is an array of blocks, holding text and tool_use blocks in order.

usage and cache writes

A request that writes to the cache with cache_control also returns usage.cache_creation with the token count per TTL (ephemeral_5m_input_tokens, ephemeral_1h_input_tokens). cache_creation_input_tokens is the sum of the two, and 1-hour cache writes are billed at a different price from 5-minute writes.

Cancelled streams and billing

Closing the connection mid-stream does not necessarily stop upstream generation. The gateway keeps reading the response to the end, within a time and output limit, and bills on the final usage the upstream reports. If a limit is hit first, it bills an estimate of what was generated up to that point.