Skip to content
Cloud Score Docs

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.

WhereAdminDeveloperNeeds a connected providerNeeds an enabled modelNeeds a gateway keyOpen in Cloud Score
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.

python
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

FieldWhat Cloud Score does
modelRequired. auto routes; a model key pins.
max_tokensRequired, an integer of 1 or more.
messagesRequired, user and assistant turns only.
systemA string or text blocks, sent as the first system message.
toolsCustom tools only (input_schema). Server tools get 400 unsupported_tool_type.
tool_choiceauto, any, none, tool; disable_parallel_tool_use maps to parallel calls.
stop_sequencesForwarded as stop.
temperatureForwarded.
streamStreams Messages SSE events. See Streaming.
metadata.user_idMapped to the end_user attribution tag.
mcp_serverscontainer too: rejected with 400 unsupported_parameter.
thinking, top_k, top_p, service_tierIgnored. Cloud Score chooses the reasoning effort.

Content blocks

BlockWhat Cloud Score does
textJoined into the message.
tool_useBecomes an assistant tool call. The arguments are your input object.
tool_resultBecomes a tool message. is_error: true adds an Error: prefix to the text.
thinking, redacted_thinkingInbound 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_controlRemoved. Cloud Score sets its own cache breakpoints.
image, document, other types400 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 order
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_stop

Errors and HTTP codes

Every error uses the Messages shape.

error body
{
  "type": "error",
  "error": { "type": "invalid_request_error", "message": "…", "code": "unsupported_parameter" }
}
StatusWhen
400Bad request, an unsupported parameter, block or tool type, or invalid_tool_history.
401Missing or invalid key.
403Blocked by AI Security or a policy.
409No candidate model, including tools_unsupported. Not retried by the SDK.
502Provider failure.
503Budget window unavailable; Retry-After says when to retry.
504deadline_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