> ## Documentation Index
> Fetch the complete documentation index at: https://docs.muxx.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat Completions

> OpenAI-compatible chat completions endpoint.

The chat completions endpoint is compatible with OpenAI's API.

## Endpoint

```
POST https://gateway.muxx.dev/v1/chat/completions
```

## Request

```bash theme={null}
curl https://gateway.muxx.dev/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "X-Muxx-Api-Key: muxx_sk_live_xxxxxxxxxxxx" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello!"}
    ],
    "temperature": 0.7,
    "max_tokens": 1000
  }'
```

## Parameters

| Parameter   | Type    | Required | Description               |
| ----------- | ------- | -------- | ------------------------- |
| model       | string  | Yes      | Model ID (e.g., `gpt-4o`) |
| messages    | array   | Yes      | Conversation messages     |
| temperature | number  | No       | Randomness (0-2)          |
| max\_tokens | integer | No       | Max output tokens         |
| stream      | boolean | No       | Enable streaming          |
| tools       | array   | No       | Function definitions      |

## Response

```json theme={null}
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1699000000,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 10,
    "total_tokens": 30
  }
}
```

## Muxx Headers

### Request Headers

| Header                 | Description                        |
| ---------------------- | ---------------------------------- |
| `X-Muxx-Api-Key`       | Your Muxx API key (required)       |
| `X-Muxx-Metadata`      | Custom metadata JSON               |
| `X-Muxx-Cache-Control` | `no-cache` to bypass cache         |
| `X-Muxx-User-Id`       | User ID for per-user rate limiting |

### Response Headers

| Header              | Description            |
| ------------------- | ---------------------- |
| `X-Muxx-Request-Id` | Unique request ID      |
| `X-Muxx-Cache`      | `HIT` or `MISS`        |
| `X-Muxx-Cost`       | Calculated cost in USD |

## Streaming

```bash theme={null}
curl https://gateway.muxx.dev/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "X-Muxx-Api-Key: muxx_sk_live_xxxxxxxxxxxx" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello!"}],
    "stream": true
  }'
```

Response is server-sent events:

```
data: {"id":"chatcmpl-abc","choices":[{"delta":{"content":"Hello"}}]}
data: {"id":"chatcmpl-abc","choices":[{"delta":{"content":"!"}}]}
data: [DONE]
```

## Supported Models

* `gpt-4o`
* `gpt-4o-mini`
* `gpt-4-turbo`
* `gpt-4`
* `gpt-3.5-turbo`
