# Create a message (/docs/api/messages)

> For AI agents, the [documentation index](https://bitrouter.ai/llms.txt) lists all pages. Append .md to a documentation URL to read its Markdown.

`POST /v1/messages`

Anthropic Messages format, so Anthropic SDKs and Claude Code work unchanged. Send `stream: true` for Server-Sent Events (`message_start`, `content_block_delta`, `message_delta`, `message_stop`). Errors use Anthropic's error shape.

## Authentication

header parameter `x-api-key` or `Authorization: Bearer <token>`.

Base URL: `https://api.spareinference.ai`

## Request body

Anthropic Messages request.

Media types: `application/json`.

* `max_tokens`: integer | null
* `messages` (required): array
* `model` (required): string
* `output_config`
* `stop_sequences`: array | null
* `stream`: boolean
* `system`
* `temperature`: number | null
* `tools`: array
* `top_k`: integer | null
* `top_p`: number | null

## Responses

* `200` Messages response (non-streaming). Streamed Messages response — Server-Sent Events. Each event has a `type` field (`message_start`, `content_block_delta`, …). (application/json, text/event-stream)
* `400` Bad request — invalid model or malformed request body. (application/json)
* `402` Payment required — insufficient balance or missing payment proof. (application/json)
* `404` No route found for the requested model. (application/json)
* `429` Rate limited by Spare Inference or by every usable upstream route. Inspect error.code to distinguish rate\_limit\_exceeded from upstream\_rate\_limited; Retry-After is included when known. (application/json)
* `500` Spare Inference internal error. (application/json)
* `502` Upstream returned an invalid response. (application/json)
* `503` The usable upstream route set is temporarily unavailable. (application/json)
* `504` Every usable upstream route timed out. (application/json)

[Full OpenAPI schema](https://bitrouter.ai/openapi.json)