Deepseek reasoning 对话格式(类Chat Completions)
Deepseek reasoning 对话格式(类Chat Completions)
推理模型 (deepseek-reasoner)
📝 简介
💡 请求示例
基础文本对话 ✅
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "deepseek-reasoner",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"reasoning_content": "让我一步步思考:\n1. 我们需要比较9.11和9.8的大小\n2. 两个数都是小数,我们可以直接比较\n3. 9.8 = 9.80\n4. 9.11 < 9.80\n5. 所以9.8更大",
"content": "9.8 is greater than 9.11."
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 15,
"total_tokens": 25
}
}
流式响应 ✅
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"deepseek-reasoner","choices":[{"index":0,"delta":{"role":"assistant","reasoning_content":"让我"},"finish_reason":null}]}
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"deepseek-reasoner","choices":[{"index":0,"delta":{"reasoning_content":"一步步"},"finish_reason":null}]}
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"deepseek-reasoner","choices":[{"index":0,"delta":{"reasoning_content":"思考:"},"finish_reason":null}]}
// ... 更多思维链内容 ...
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"deepseek-reasoner","choices":[{"index":0,"delta":{"content":"9.8"},"finish_reason":null}]}
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"deepseek-reasoner","choices":[{"index":0,"delta":{"content":" is greater"},"finish_reason":null}]}
// ... 更多最终答案内容 ...
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"deepseek-reasoner","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
📮 请求
端点
POST /v1/chat/completions
鉴权方法
Authorization: Bearer $NEWAPI_API_KEY
$DEEPSEEK_API_KEY
是您的 API 密钥。请求体参数
messages
model
max_tokens
stream
不支持的参数
支持的功能
不支持的功能
📥 响应
成功响应
id
object
created
model
choices
index
: 选项索引message
: 包含角色、思维链内容和最终回答的消息对象role
: 角色,值为 "assistant"reasoning_content
: 思维链内容content
: 最终回答内容finish_reason
: 完成原因usage
prompt_tokens
: 提示使用的 token 数completion_tokens
: 补全使用的 token 数total_tokens
: 总 token 数📝 上下文拼接说明

如果您在输入的 messages 序列中,传入了reasoning_content,API 会返回 400 错误。因此,请删除 API 响应中的 reasoning_content 字段,再发起 API 请求,方法如下方使用示例所示。
修改于 2025-05-30 01:37:55