# Create a chat completion (/docs/api/chat-completions)

> 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/chat/completions`

OpenAI Chat Completions format. Send `stream: true` for Server-Sent Events, ending with `data: [DONE]`. The `x-bitrouter-request-id` response header identifies the request for [settlement](https://bitrouter.ai/docs/api/settlement).

## Authentication

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

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

## Request body

Chat completion request.

Media types: `application/json`.

* `frequency_penalty`: number | null
* `max_completion_tokens`: integer | null
* `max_tokens`: integer | null
* `messages` (required): array
* `model` (required): string
* `parallel_tool_calls`: boolean | null
* `presence_penalty`: number | null
* `reasoning_effort`
* `response_format`
* `seed`: integer | null
* `stop`
* `store`: boolean | null
* `stream`: boolean
* `stream_options`
* `temperature`: number | null
* `tools`: array
* `top_p`: number | null

## Responses

* `200` Chat completion response (non-streaming). Streamed chat completion — Server-Sent Events with one `ChatCompletionChunk` per `data:` line, terminated by `data: [DONE]`. (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)