Anthropic Messages endpoint
Point the official Anthropic SDK at the Cloud Score gateway: POST /v1/messages takes x-api-key, routes when model is auto, and returns Messages-shaped bodies, SSE events and errors with a dex_routing block.
On this page
What it is
POST /v1/messages accepts the Anthropic Messages API, so clients that speak it (the Anthropic SDK, agent frameworks, Claude Code) work against the gateway by changing the base URL and the key. The request is translated into the same pipeline as /v1/chat/completions: guarded, routed, cached, recorded and billed. The reply comes back in Messages shape with an extra dex_routing block.
It is a stateless subset: Cloud Score never runs your tools and keeps no conversation between calls. Send the full history each time.
Point the SDK at the gateway
Send the gateway key in x-api-key (the Anthropic SDK does this for you) or as Authorization: Bearer dex_sk_…. The model can be auto or a model key.
import os
import anthropic
client = anthropic.Anthropic(
base_url="http://localhost:7001",
api_key=os.environ["DEX_API_KEY"], # sent as x-api-key
)
message = client.messages.create(
model="auto",
max_tokens=1024,
messages=[{"role": "user", "content": "Summarize this quarter in two sentences."}],
)
print(message.content[0].text)Request shape
| Field | What Cloud Score does |
|---|---|
model | Required. auto routes; a model key pins. |
max_tokens | Required, an integer of 1 or more. |
messages | Required, user and assistant turns only. |
system | A string or text blocks, sent as the first system message. |
tools | Custom tools only (input_schema). Server tools get 400 unsupported_tool_type. |
tool_choice | auto, any, none, tool; disable_parallel_tool_use maps to parallel calls. |
stop_sequences | Forwarded as stop. |
temperature | Forwarded. |
stream | Streams Messages SSE events. See Streaming. |
metadata.user_id | Mapped to the end_user attribution tag. |
mcp_servers | container too: rejected with 400 unsupported_parameter. |
thinking, top_k, top_p, service_tier | Ignored. Cloud Score chooses the reasoning effort. |
Content blocks
| Block | What Cloud Score does |
|---|---|
text | Joined into the message. |
tool_use | Becomes an assistant tool call. The arguments are your input object. |
tool_result | Becomes a tool message. is_error: true adds an Error: prefix to the text. |
thinking, redacted_thinking | Inbound only: passed to Claude models, dropped for other providers; the request trace records thinking_blocks_dropped. Replies carry text and tool_use blocks only, never thinking blocks (thinking is off on tool-loop turns after the first). |
cache_control | Removed. Cloud Score sets its own cache breakpoints. |
image, document, other types | 400 unsupported_content_type. |
Streaming
Text is sent once the answer has passed output checks, so it arrives after the check rather than token by token from the model. Each tool_use is sent whole in a single input_json_delta. Usage is in message_delta.
event: message_start
event: content_block_start (text, once the answer has passed checks)
event: content_block_delta (text_delta)
event: content_block_stop
event: content_block_start (tool_use, input {})
event: content_block_delta (one input_json_delta with the whole arguments)
event: content_block_stop
event: message_delta (stop_reason and usage)
event: message_stopErrors and HTTP codes
Every error uses the Messages shape.
{
"type": "error",
"error": { "type": "invalid_request_error", "message": "…", "code": "unsupported_parameter" }
}| Status | When |
|---|---|
400 | Bad request, an unsupported parameter, block or tool type, or invalid_tool_history. |
401 | Missing or invalid key. |
403 | Blocked by AI Security or a policy. |
409 | No candidate model, including tools_unsupported. Not retried by the SDK. |
502 | Provider failure. |
503 | Budget window unavailable; Retry-After says when to retry. |
504 | deadline_exceeded. |
A failure after the stream has started arrives as an error event with the same body.
Good to know
Good to know
Attribute spend with the X-Dex-* headers, as on the other endpoints. Message ids are msg_ plus the request id, and the request shows as Anthropic Messages under Object on /logs.
Related
- OpenAI-compatible endpointPoint the official OpenAI SDK at the Cloud Score gateway: POST /v1/chat/completions routes when model is auto, pins when it is a model key, accepts dex_strategy, and answers with a dex_routing block, HTTP 403 on a block, 409 when no tool-capable model is available, and 502 on any other failure.
- OpenAI Responses endpointPoint the OpenAI SDK or the OpenAI Agents SDK at the Cloud Score gateway: POST /v1/responses is a stateless subset that routes when model is auto and rejects stateful parameters with a 400.
- Attribute cost to teams and appsTag every request with team, application, agent, environment, and end_user so Usage & cost can break spend down by them as reported tags, budgets can cap a team or an app, and alert rules can watch them.
- ObservabilityThe per-request audit trail and the gateway's health: filter the request list, open a request for its route, attempts, cost and savings receipt, and read latency, outcomes and retries on Gateway health.