Messages (Anthropic format)
POST /r/{router_slug}/v1/messages
Send messages, a model placeholder, and max_tokens for the output limit. The Anthropic SDK uses the router root as its base URL and appends /v1/messages. The following cURL example uses the full endpoint and the router key in x-api-key. Set the URL and key · Python and Node.js examples.
curl "$DODO_ROUTER_URL/v1/messages" \
-H "x-api-key: $DODO_ROUTER_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "default",
"max_tokens": 100,
"messages": [{"role": "user", "content": "Reply with pong."}]
}'
Read the response's content array by block type. A text block contains text. A tool_use block contains a tool ID, name and input. Send the result in a user message with a tool_result block referencing that ID. A completed text response has fields like these.
{
"id": "msg_5a8d090908f8feb21be52ef0", "type": "message", "role": "assistant",
"content": [{"type": "text", "text": "pong"}],
"model": "gpt-5.5", "stop_reason": "end_turn", "stop_sequence": null,
"usage": {"input_tokens": 13, "output_tokens": 5}
}
The completed response identifies the serving model, which can be from a different provider. DodoRouter translates system prompts, multi-block messages, and tool history for the selected step. Base64 image and PDF blocks have image_url and file representations for OpenAI-family routes. Support for other document sources and cache breakpoints depends on the upstream format. Open the request trace to see which fields a particular attempt translated or dropped. Use Messages with Claude Code.
Streaming
Add "stream":true to the JSON body and pass -N to cURL. Read the Anthropic SSE lifecycle beginning with message_start. Join content_block_delta events by block index, then read message_delta and message_stop. Anthropic rate-limit response headers are forwarded when available.
Before the stream opens, configuration or provider failures can return JSON with HTTP 400 or 502. After it opens, handle event: error even if a message_stop follows. For stored-response retries, use a non-streaming request. Idempotency.
Count input tokens
POST /r/{router_slug}/v1/messages/count_tokens
Use this endpoint to size a Messages prompt before sending it. Include the same messages, system prompt and tools you intend to send.
curl "$DODO_ROUTER_URL/v1/messages/count_tokens" \
-H "x-api-key: $DODO_ROUTER_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{"model":"default","messages":[{"role":"user","content":"Hello!"}]}'
The result contains an integer input_tokens. DodoRouter asks the first Anthropic step to count using its configured model when its key is available. If that lookup or provider request fails, or the chain has no Anthropic step, DodoRouter estimates from the byte size of the messages, system prompt and tools. Both paths return the same JSON shape, so use the count for sizing and read the generation response's usage for actual usage.