Skip to content

Chat Completions ​

POST /v1/chat/completions 用于创建聊天补全,是大多数客户端和 SDK 的默认接口。

请求参数 ​

字段类型必填说明
modelstring是平台模型名称
messagesarray是对话消息列表
streamboolean否是否使用流式响应
temperaturenumber否采样温度,是否生效取决于模型
top_pnumber否nucleus sampling 参数
max_tokensnumber否最大输出 Token,部分模型使用其它字段
max_completion_tokensnumber否部分推理模型使用的最大完成 Token
toolsarray否工具或函数定义
tool_choicestring/object否工具选择策略
response_formatobject否JSON 或结构化输出要求

Message 对象 ​

字段说明
rolesystem、user、assistant、tool 等
content文本或多模态 content part 数组
name可选名称
tool_calls模型发起的工具调用
tool_call_id工具返回消息关联的调用 ID

响应 ​

非流式响应通常包含 id、object、created、model、choices 和 usage。流式响应按事件返回增量 delta。

请求示例 ​

bash
curl https://api.cloudaikit.com/v1/chat/completions \
  -H "Authorization: Bearer sk-your-token" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [{"role": "user", "content": "你好"}],
    "temperature": 0.2
  }'

非流式响应中的文本通常位于 choices[0].message.content。使用工具调用时,应执行 choices[0].message.tool_calls 中的函数,再把结果作为 role: tool 的消息发回。

兼容差异 ​

工具调用、结构化输出、图片输入、音频输入、推理参数和缓存计费字段取决于模型与渠道。若字段被忽略或报错,请查看日志中的实际渠道,并查询对应模型能力。