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

# Chat Completions API

> OpenAI-compatible chat completions endpoint for routing LLM calls through the Unbound gateway

## Overview

The Unbound Security AI Gateway provides a RESTful API that allows you to integrate AI capabilities into your applications while maintaining enterprise-grade security, cost control, and compliance. The API is compatible with OpenAI's Chat Completions API format, making it easy to migrate existing integrations.

## Base URL

All API requests should be made to:

```
https://api.getunbound.ai/v1
```

## Authentication

The Unbound API uses Bearer token authentication. Include your API key in the Authorization header:

```
Authorization: Bearer YOUR_API_KEY
```

<Note>
  Get your API key at [gateway.getunbound.ai/connect](https://gateway.getunbound.ai/connect).
</Note>

## Chat Completions

Create a completion for the provided chat messages.

### Endpoint

```http theme={null}
POST /v1/chat/completions
```

### Request Headers

| Header          | Type   | Required | Description                    |
| --------------- | ------ | -------- | ------------------------------ |
| `Authorization` | string | Yes      | Bearer token with your API key |
| `Content-Type`  | string | Yes      | Must be `application/json`     |

### Request Body

| Parameter     | Type    | Required | Description                                     |
| ------------- | ------- | -------- | ----------------------------------------------- |
| `model`       | string  | Yes      | The model to use for completion                 |
| `messages`    | array   | Yes      | Array of message objects                        |
| `max_tokens`  | integer | No       | Maximum tokens to generate (default: 1000)      |
| `temperature` | number  | No       | Sampling temperature (0.0 to 2.0, default: 1.0) |
| `stream`      | boolean | No       | Whether to stream the response (default: false) |

### Message Object

| Parameter | Type   | Required | Description                                                |
| --------- | ------ | -------- | ---------------------------------------------------------- |
| `role`    | string | Yes      | Role of the message sender (`user`, `assistant`, `system`) |
| `content` | string | Yes      | Content of the message                                     |

### Example Request

```bash theme={null}
curl -X POST 'https://api.getunbound.ai/v1/chat/completions' \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4-20250514",
    "messages": [
      {
        "role": "user",
        "content": "Help me plan meals for the week."
      }
    ]
  }'
```

### Example Response

```json theme={null}
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "anthropic/claude-sonnet-4-20250514",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Here's a balanced meal plan for the week..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 15,
    "completion_tokens": 245,
    "total_tokens": 260
  }
}
```

### Multi-turn Conversation

```bash theme={null}
curl -X POST 'https://api.getunbound.ai/v1/chat/completions' \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4-20250514",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful coding assistant."
      },
      {
        "role": "user",
        "content": "How do I create a REST API in Python?"
      },
      {
        "role": "assistant",
        "content": "I can help you create a REST API in Python using Flask or FastAPI. Which framework would you prefer?"
      },
      {
        "role": "user",
        "content": "Let's use FastAPI"
      }
    ],
    "max_tokens": 1000,
    "temperature": 0.7
  }'
```

### Streaming Response

```bash theme={null}
curl -X POST 'https://api.getunbound.ai/v1/chat/completions' \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4-20250514",
    "messages": [
      {
        "role": "user",
        "content": "Write a Python function to calculate fibonacci numbers"
      }
    ],
    "stream": true
  }'
```

<CardGroup cols={2}>
  <Card title="List Models" icon="brain" href="/integrations/api-models">
    Retrieve available models and their pricing from the gateway
  </Card>

  <Card title="Python SDK" icon="python" href="/integrations/python-sdk">
    Use the Unbound Python SDK for drop-in OpenAI compatibility
  </Card>
</CardGroup>
