# Create chat completion (/docs/reference/openai-compatible/createChatCompletion)

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

`POST /v1/chat/completions`

Creates a chat completion for the given messages. Drop-in replacement for the OpenAI Chat Completions API — accepts the same request schema and returns the same response format, including `usage` with token counts.

The router resolves the requested model to an upstream provider, forwards the request, and returns the response. Supports both synchronous and streaming modes.

When `stream: true`, the response is sent as Server-Sent Events (SSE) where each `data` line contains a `ChatCompletionChunk` JSON object. The stream ends with `data: [DONE]`.

## Authentication

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

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

## Request body

Chat completion request. The router forwards a slightly enriched version of this body to the resolved upstream provider.

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 BitRouter 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` BitRouter 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-docs-staging.up.railway.app/openapi.json)