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

# Chat Completions

> 通过 HingNet AI 兼容 OpenAI 的对话补全与工具调用接口。

<style>
  {`
    /* 仅本页：缩小正文字体（不影响代码块） */
    #chatcom-page p,
    #chatcom-page li,
    #chatcom-page blockquote {
      font-size: 0.95rem;
      line-height: 1.65;
    }
    #chatcom-page h2 {
      font-size: 1.15rem;
    }
    `}
</style>

<div id="chatcom-page">
  `POST /v1/chat/completions` 是最常用的对话生成接口，支持流式输出、函数调用（tools/functions）以及 JSON mode。

  ## 请求示例

  ```bash theme={null}
  curl -X POST "$BASE_URL/v1/chat/completions" \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-4o-mini",
      "messages": [
        {"role": "system", "content": "你是 HingNet AI 的产品助理。"},
        {"role": "user", "content": "用三句话介绍 HingNet AI。"}
      ],
      "temperature": 0.7
    }'
  ```

  ## 常见用法

  * **流式输出**：在请求体中设置 `stream: true`。cURL 请添加 `-N` 选项，Python 端可组合 `requests.post(..., stream=True)` 逐行读取。
  * **函数调用**：通过 `tools` 与 `tool_choice` 描述可调用的函数，后续在响应中解析 `tool_calls` 并执行业务逻辑。
  * **JSON 约束**：配合 `response_format` 设置为 `{"type": "json_schema"}`，可让模型严格返回结构化数据。

  <Callout type="info">
    HingNet AI 会自动对齐常见第三方兼容实现中的差异字段，减少模型切换带来的适配成本。
  </Callout>
</div>
