# Chat Completions

OpenAI-compatible chat completions.

`POST /api/v1/chat/completions`

## Overview

Send OpenAI-compatible chat-completions requests through a configured OpenAI-compatible upstream. Streaming is supported when the upstream supports it.

## Parameters

- `model` (string) — required: Model ID, e.g. gpt-5.6 or claude-opus-5.
- `messages` (array) — required: Conversation history in OpenAI message format.
- `stream` (boolean): Stream tokens as server-sent events.
- `temperature` (number): Sampling temperature between 0 and 2.
- `tools` (array): Tool definitions the model may call.

## Example

```bash
curl -X POST https://capi.ai/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.6",
    "messages": [{"role": "user", "content": "Hello"}]
  }'
```

## Response

```json
{
  "id": "chatcmpl_9f2b41",
  "object": "chat.completion",
  "model": "gpt-5.6",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "..." },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 42, "completion_tokens": 118, "total_tokens": 160 }
}
```
