Chat Completions
messages、tool_calls 与兼容格式
端点
POST https://www.yunqiai.chat/v1/chat/completions
使用 Authorization: Bearer <API_KEY> 和 JSON 请求体。不同模型的可用参数见型号页,客户端自动识别结果仅供参考。
{
"model": "kimi-k3",
"messages": [{"role":"user","content":"仅回复 READY"}],
"max_tokens": 4096,
"stream": false
}字段与响应
| 字段 | 说明 |
|---|---|
| messages | 按顺序传递 system、user、assistant、tool 消息 |
| max_tokens / max_completion_tokens | 使用目标模型接受的字段,不同时发送两个预算字段 |
| tools | type=function,定义放在 function 内,与 Responses 的扁平函数格式不同 |
| tool_choice | 自动、禁用或指定工具,受型号约束 |
| response_format | 支持时设置 JSON object / JSON Schema,不是 Responses 的 text.format |
| stream | true 返回 SSE,需逐帧解析 |
响应需读取 choices[].message.content、tool_calls、finish_reason 和 usage。finish_reason=length 表示截断,tool_calls 表示需要执行工具。若返回 reasoning_content,请将其作为推理内容单独处理,不并入最终正文或普通 content。
工具历史
工具定义示例为 {"type":"function","function":{"name":"lookup","description":"...","parameters":{"type":"object","properties":{}}}}。
收到工具调用后,将完整 assistant 消息追加到 messages,保留调用 ID,再为每个调用追加 {"role":"tool","tool_call_id":"原调用 id","content":"结果字符串"}。后续请求沿用同一型号。
图片与流式
支持视觉的型号使用 content 数组,文本块为 {"type":"text","text":"问题"},图片块为 {"type":"image_url","image_url":{"url":"data:image/png;base64,<BASE64>"}}。图片理解需同时得到模型支持,接口接受该字段并不能验证图片是否被读取。
流式数据的正文通常在 choices[].delta.content,工具参数需要按调用下标累积,最后解析成 JSON。data: [DONE] 为流结束标记;收到标记前的断开不当作完整成功。
GPT 的工具与文件调用使用Responses。gpt-6-astra 在 Chat 接口中的文本兼容不包含工具调用。