# Chat Completions API

聊天补全端点为大语言模型提供文本及多模态输入交互。

## 请求地址

```http
POST https://api.tokenlio.ai/v1/chat/completions
```

## 请求头

| 字段 | 类型 | 说明 |
|---|---|---|
| `Authorization` | string | `Bearer tk-your-api-key` |
| `Content-Type` | string | `application/json` |

## 核心请求参数

| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| `model` | string | 是 | - | 模型名称（如 `gpt-4-turbo`、`claude-3-5-sonnet`） |
| `messages` | array | 是 | - | 消息上下文列表 |
| `temperature` | number | 否 | `1` | 采样温度 (0.0 ~ 2.0) |
| `max_tokens` | integer | 否 | - | 最大输出 token 数 |
| `stream` | boolean | 否 | `false` | 是否开启流式响应 |

## 响应示例

```json
{
  "id": "chatcmpl-8abc123",
  "object": "chat.completion",
  "created": 1709123456,
  "model": "gpt-4-turbo",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "你好！我是通过 Tokenlio API 网关调用的模型。"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 16,
    "total_tokens": 28
  }
}
```
