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

# 创建聊天补全

> 根据消息列表生成回复

使用 Bearer API Key。请求体为 JSON。

| 字段                                       | 类型                  | 必填 | 说明                                                            |
| ---------------------------------------- | ------------------- | -- | ------------------------------------------------------------- |
| `model`                                  | string              | 是  | 实时模型页中的模型 ID。                                                 |
| `messages`                               | array               | 是  | 按顺序排列的 system、developer、user、assistant 或 tool 消息；内容可为字符串或内容块。 |
| `temperature`                            | number              | 否  | 采样温度。通常不要与 `top_p` 同时调整。                                      |
| `top_p`                                  | number              | 否  | 核采样概率质量。                                                      |
| `max_completion_tokens`                  | integer             | 否  | 生成 token 上限。                                                  |
| `stream`                                 | boolean             | 否  | 返回 SSE 增量；默认 `false`。                                         |
| `stop`                                   | string/array        | 否  | 停止序列。是否支持取决于模型。                                               |
| `n`                                      | integer             | 否  | 每个输入生成的选项数。                                                   |
| `presence_penalty` / `frequency_penalty` | number              | 否  | 控制重复与新主题倾向。                                                   |
| `response_format`                        | object              | 否  | 文本、JSON 对象或 JSON Schema 输出配置。                                 |
| `tools` / `tool_choice`                  | array/object/string | 否  | 可调用工具定义及选择策略。                                                 |
| `seed`, `user`, `metadata`               | mixed               | 否  | 可复现提示、用户标识和元数据；支持情况依模型而定。                                     |

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.bianxie.ai/v1/chat/completions \
    -H "Authorization: Bearer API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "your-model",
      "messages": [{"role": "user", "content": "你好"}],
      "temperature": 0.7
    }'
  ```

  ```python Python theme={null}
  client.chat.completions.create(model="your-model", messages=[{"role":"user","content":"你好"}])
  ```

  ```javascript Node.js theme={null}
  await client.chat.completions.create({ model: "your-model", messages: [{ role: "user", content: "Hello" }] });
  ```
</CodeGroup>

非流式响应包含 `id`、`object`、`created`、`model`、`choices[]` 和 `usage`。每个 choice 包含 `index`、`message` 与 `finish_reason`。流式响应返回增量 `choices[].delta`，直至结束事件。
