API Reference

Create Message

Creates a model response using the Anthropic Claude Messages API format. Supports streaming via `stream: true`. Automatically routes to the best available provider (Anthropic, Google, OpenAI-compatible). Set `ANTHROPIC_BASE_URL` to this server's base URL in Claude Code or any Anthropic SDK to use Yolo Router as a drop-in replacement.

POST
/v1/messages

Authorization

ApiKeyAuth
AuthorizationBearer <token>

Your Yolo Router API key. Format: Bearer sk-...

In: header

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

application/json

application/json

application/json

curl -X POST "https://api.yolorouter.com/v1/messages" \  -H "Content-Type: application/json" \  -d '{    "model": "claude-3-5-sonnet-20241022",    "max_tokens": 1024,    "messages": [      {        "role": "user",        "content": "Hello!"      }    ]  }'
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "model": "claude-3-5-sonnet-20241022",
  "content": [
    {
      "type": "text",
      "text": "string",
      "thinking": "string",
      "id": "string",
      "name": "string",
      "input": {},
      "tool_use_id": "string",
      "content": null,
      "source": {
        "type": "base64",
        "media_type": "image/png",
        "data": "string",
        "url": "string"
      }
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": "string",
  "usage": {
    "input_tokens": 0,
    "output_tokens": 0
  }
}
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "Invalid request"
  }
}
{
  "type": "error",
  "error": {
    "type": "authentication_error",
    "message": "Invalid API key"
  }
}
{
  "type": "error",
  "error": {
    "type": "insufficient_quota",
    "message": "Quota exceeded"
  }
}
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "Invalid request"
  }
}