multi-router.aidocs

API Reference

Messages

POST /v1/messages: Anthropic-compatible requests, through routers or a Claude Proxy.

POST /v1/messages accepts requests in the Anthropic Messages format, so Anthropic SDKs and tools work with Multi-Router by changing their base URL to https://api.multi-router.ai. It needs the inference scope, accepts bodies up to 32 MB, accepts the key in x-api-key as well as Authorization, and returns errors in the Anthropic format.

Routing

A Messages request is served in one of two ways:

RequestServed by
A router or alias in the model fieldThat router, as on Chat Completions.
x-mr-router names a Claude ProxyThe Claude Proxy, which serves the request on its route with the route's model id and key.
x-mr-router names an Adaptive RouterThe Adaptive Router, which plans it with its rules. See Adaptive Router.
OtherwiseThe router named in x-mr-router, or the model in the model field.

Request body

The body takes the Anthropic Messages fields:

FieldType
modelstring, required
A router, alias, or model, as on Chat Completions.
messagesarray, required
The conversation, with text, image and tool content blocks.
max_tokensinteger, required
The most tokens to generate.
systemstring or array
The system prompt, as text or content blocks with cache control.
streamboolean
Streams the reply as server-sent events.
temperaturenumber
Sampling temperature.
top_pnumber
Nucleus sampling.
top_kinteger
Top-k sampling.
stop_sequencesarray
Stop sequences.
toolsarray
Tools with an input schema.
tool_choiceobject
auto, any, a named tool, or none.
thinkingobject
Extended thinking, with a token budget.
metadata.user_idstring
The caller's end user, recorded in Traffic as the customer id.
prompt_variablesobject
Values for the router's bound prompt variables.

Example

A request to a router and its response, which echoes the request's model field:

Requestbash
curl https://api.multi-router.ai/v1/messages \
  -H "x-api-key: $MR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "multi-router/rt_9Hk3Ws7PzQ",
    "max_tokens": 200,
    "messages": [{ "role": "user", "content": "Summarize ticket 4521 in one sentence." }]
  }'
Response 200json
{
  "id": "msg_01Kd2Qx9WmB4Tn6Ls",
  "type": "message",
  "role": "assistant",
  "model": "multi-router/rt_9Hk3Ws7PzQ",
  "content": [{ "type": "text", "text": "The customer was charged twice for March and wants a refund." }],
  "stop_reason": "end_turn",
  "usage": { "input_tokens": 412, "output_tokens": 18 }
}

Errors

Errors use the Anthropic format, with a type that follows the status: 400 invalid_request_error, 401 authentication_error, 403 permission_error, 404 not_found_error, 413 request_too_large, 429 rate_limit_error, 503 overloaded_error, and api_error for other statuses. The message carries the detail.

Chat CompletionsProxy Endpoints
Was this helpful?