聊天补全
核心对话接口,兼容 OpenAI Chat Completions 格式,支持多模态输入、流式输出、工具调用与推理模型。
请求
curl https://test.kailin.com.cn/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-你的令牌" \
-d '{
"model": "deepseek-v4-1-flash-261017",
"messages": [
{ "role": "system", "content": "你是一个简洁的助手" },
{ "role": "user", "content": "你好" }
],
"stream": false
}'
请求REQUEST
POST
https://test.kailin.com.cn/v1/chat/completions响应RESPONSE
填写参数并发送请求,响应会显示在这里
请求体参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名称,见 列出模型 |
messages | array | 是 | 对话消息数组,见下方消息结构 |
stream | boolean | 否 | 是否流式输出(SSE),默认 false |
temperature | number | 否 | 采样温度 0–2,默认 1,越低越确定 |
top_p | number | 否 | 核采样,与 temperature 二选一调整 |
max_tokens | number | 否 | 最大生成 token 数(部分新模型改用 max_completion_tokens) |
stop | string / array | 否 | 停止序列,最多 4 个 |
tools | array | 否 | 工具(函数)定义列表,见工具调用 |
tool_choice | string / object | 否 | auto / none / required / 指定工具 |
response_format | object | 否 | {"type": "json_object"} 或 {"type": "json_schema", ...} |
seed | integer | 否 | 随机种子,尽量复现输出 |
frequency_penalty | number | 否 | -2.0–2.0,降低重复 |
presence_penalty | number | 否 | -2.0–2.0,鼓励新话题 |
reasoning_effort | string | 否 | 推理模型思考力度:low / medium / high |
user | string | 否 | 终端用户标识,便于风控 |
messages 消息结构
| 字段 | 类型 | 说明 |
|---|---|---|
role | string | system / user / assistant / tool |
content | string / array | 字符串,或多模态内容数组(见多模态输入) |
name | string | 可选,参与者名称 |
tool_calls | array | assistant 消息中模型发起的工具调用 |
tool_call_id | string | tool 角色消息必填,对应被响应的调用 ID |
响应(非流式)
{
"id": "chatcmpl-B3xK1abc123",
"object": "chat.completion",
"created": 1730000000,
"model": "deepseek-v4-1-flash-261017",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!有什么可以帮你的吗?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 12,
"total_tokens": 32
}
}
| 字段 | 说明 |
|---|---|
choices[].message.content | 模型回复文本 |
choices[].finish_reason | stop 正常结束 / length 达到上限 / tool_calls 需要执行工具 |
usage | token 计量,计费依据 |
usage.completion_tokens_details.reasoning_tokens | 推理模型返回的思考 token 数 |
流式响应
"stream": true 时返回 SSE 事件流:
data: {"id":"chatcmpl-xxx","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","choices":[{"index":0,"delta":{"content":"你好"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
增量内容在 choices[].delta.content,最后以 data: [DONE] 结束。最后一个 chunk 的 usage 字段可能携带 token 用量(取决于上游)。