Claude Messages

Use the Claude-compatible Messages endpoint for clients that send Anthropic-style message payloads.

POST https://getrouter.ai/v1/messages

Basic request

curl https://getrouter.ai/v1/messages \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MODEL_ID",
    "max_tokens": 512,
    "system": "Answer clearly and concisely.",
    "messages": [
      {"role": "user", "content": "Explain the purpose of a Base URL."}
    ]
  }'

The response follows a Claude-compatible message shape with content blocks and usage information when available.

Required fields

FieldDescription
modelClaude-compatible model ID
messagesConversation messages
max_tokensMaximum output token count

Optional fields

The API schema includes fields such as:

  • system
  • temperature, top_p, and top_k
  • stream
  • stop_sequences
  • tools and tool_choice
  • thinking
  • context_management
  • output_config and output_format
  • metadata
  • speed and service_tier

Support is model-dependent. Do not send an option only because it appears in the schema; confirm the selected model supports it.

Streaming

Set stream to true for Claude-compatible streaming when supported:

{
  "model": "MODEL_ID",
  "max_tokens": 512,
  "stream": true,
  "messages": [
    {"role": "user", "content": "Write a short release note."}
  ]
}

Use a Claude event parser rather than a Chat Completions or Responses parser.

Tool and thinking support

Claude-compatible tool definitions, tool result blocks, and thinking configuration require a model with matching capabilities. Test the complete workflow before enabling it in unattended agents.

Warning

A Claude model ID used through an OpenAI-compatible endpoint and the same model used through /v1/messages can require different request and response handling. Configure the protocol expected by your client.

Tool integrations

Tools such as Claude-compatible coding clients may require additional environment variables or provider settings. Follow the dedicated guide under Integrations instead of replacing only the hostname.

Next steps