Open A I CompatibleCreate chat completion

Create chat completion

1 min readEdit this page
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].

Authorization

x-api-key<token>

Anthropic-style API key header.

In: header

Request Body

application/json

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

TypeScript Definitions

Use the request body type in TypeScript.

Chat Completions request body (https://platform.openai.com/docs/api-reference/chat/create).

pub so downstream crates (notably bitrouter-cloud) can derive an OpenAPI schema from the canonical wire shape without redeclaring it.

Response Body

application/json

application/json

application/json

curl -X POST "https://example.com/v1/chat/completions" \  -H "Content-Type: application/json" \  -d '{    "messages": [      {        "role": "string"      }    ],    "model": "string"  }'
{  "choices": [    {      "finish_reason": "string",      "index": 0,      "message": {        "content": "string",        "role": "string"      }    }  ],  "created": 0,  "id": "string",  "model": "string",  "object": "string",  "usage": {    "completion_tokens": 0,    "prompt_tokens": 0,    "total_tokens": 0  }}
{  "error": {    "code": "string",    "message": "string"  }}
{  "error": {    "code": "string",    "message": "string"  }}
{  "error": {    "code": "string",    "message": "string"  }}

How is this guide?