端点
POST /v1/chat/completions
镜像 chat-completions 约定的次要端点。来自 /v1/messages 的所有模型与积分池规则同样适用——只是请求和响应的形态不同。
什么时候用这个端点
当你已有客户端期望的就是这种请求/响应形态、并且想直接对接而不重写调用点时,使用 /v1/chat/completions。新代码我们建议使用 /v1/messages——它原生支持内容块、工具、深度思考和视觉;本端点只暴露其中一部分。
基本调用
curl https://caicaini.com/v1/chat/completions \
-H "Authorization: Bearer cai_api_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "caicaini/auto",
"messages": [
{"role": "system", "content": "You are concise."},
{"role": "user", "content": "Two reasons to use TypeScript over JS in 2026?"}
],
"max_tokens": 256
}'请求字段
| 字段 | 类型 | 说明 |
|---|---|---|
| model必填 | string | 五个虚拟 ID 之一。常规流量默认使用 caicaini/auto。 |
| messages必填 | array | developers.docs.chatCompletions.fieldMessagesDesc |
| max_tokens | integer | 完成 token 的硬上限。强烈建议设置。 |
| temperature | number 0–2 | 默认 1。 |
| top_p | number 0–1 | 核采样。 |
| stop | string | string[] | 最多四个停止序列。 |
| stream | boolean | 为 true 时,服务端流式输出 SSE 数据块。详见 流式响应。 |
| tools | Tool[] | chat-completions 工具格式的函数定义。详见 工具。 |
| tool_choice | "none" | "auto" | object | 约束工具选择。 |
| response_format | { type: "json_object" } | 强制模型返回合法 JSON。请在系统提示里同时给出 schema 指令。 |
| user | string | 终端用户标识。会转发到滥用排查和报表系统。 |
响应
响应 · 200 OK
{
"id": "chatcmpl_01H8fkx2N3p4q5r6s7t8u9v",
"object": "chat.completion",
"created": 1746748800,
"model": "caicaini/auto",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "1) Catch class-of-bug at compile time. 2) Editor knows your shape."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 31,
"completion_tokens": 22,
"total_tokens": 53,
"credits_consumed": 27
}
}choices[0].message.content包含 assistant 的文本回复。choices[0].finish_reason为stop、length、tool_calls、content_filter之一。usage.credits_consumed为权威值——与等价的/v1/messages调用一致。
本端点的流式响应
流式使用 chat-completions 数据块格式:以 chat.completion.chunk 事件流式发送,并以字面帧 data: [DONE] 结束。完整的事件参考与解析示例见 流式响应 页面。