对话补全 (Chat)
DeepSeek 系列
DeepSeek 通用与 R1 推理模型
适用模型
| 模型 | 类型 | 上下文 | 最大输出 |
|---|---|---|---|
deepseek-v4-flash | 通用 | 1,000,000 | 128,000 |
deepseek-v4-pro | 通用 | 1,000,000 | 128,000 |
deepseek-v3.2 | 通用 | 128,000 | 8,000 |
DeepSeek-R1 | 推理 | 128,000 | 16,000 |
DeepSeek-R1-0528 | 推理 | 128,000 | 16,000 |
公开协议
DeepSeek 官方 API 与 OpenAI 格式兼容,因此统一调用 POST /v1/chat/completions。R1 模型的推理内容可能出现在 reasoning_content,不要把该字段回传到下一轮 messages;只回传最终 content 和工具调用消息。
{
"model": "DeepSeek-R1-0528",
"messages": [{"role": "user", "content": "证明根号 2 是无理数"}],
"stream": true,
"max_tokens": 4096
}请求参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
model | string | 是 | - | 本页适用模型之一 |
messages | array | 是 | - | 对话消息列表 |
messages[].role | string | 是 | - | system、user、assistant 或 tool |
messages[].content | string | 是 | - | 消息文本 |
stream | boolean | 否 | false | 是否启用 SSE 流式输出 |
max_tokens | integer | 否 | 模型默认 | 最大输出 Token 数 |
temperature | number | 否 | 1 | 采样温度,范围 [0, 2) |
top_p | number | 否 | 1 | 核采样阈值,范围 (0, 1] |
frequency_penalty | number | 否 | 0 | 频率惩罚,范围 [-2, 2] |
presence_penalty | number | 否 | 0 | 存在惩罚,范围 [-2, 2] |
stop | string/array | 否 | - | 停止序列 |
tools | array | 否 | - | 函数工具定义 |
tool_choice | string/object | 否 | auto | 工具选择策略 |
response_format | object | 否 | {"type":"text"} | 可设置 JSON Object 输出 |
响应参数
| 参数 | 类型 | 说明 |
|---|---|---|
id | string | 请求 ID |
object | string | chat.completion 或 chat.completion.chunk |
created | integer | Unix 时间戳 |
model | string | 模型名称 |
choices[].message.content | string/null | 最终答案 |
choices[].message.reasoning_content | string/null | R1 模型的推理内容 |
choices[].message.tool_calls | array | 工具调用列表 |
choices[].finish_reason | string | stop、length 或 tool_calls |
usage.prompt_tokens | integer | 输入 Token 数 |
usage.completion_tokens | integer | 输出 Token 数,包含模型返回的推理 Token |
usage.total_tokens | integer | 总 Token 数 |
{
"id": "chatcmpl_01H...",
"object": "chat.completion",
"created": 1783819200,
"model": "DeepSeek-R1-0528",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"reasoning_content": "采用反证法,假设根号 2 可以写成最简分数……",
"content": "假设 √2=a/b 且 a、b 互质……因此 √2 是无理数。"
},
"finish_reason": "stop"
}],
"usage": {"prompt_tokens": 16, "completion_tokens": 230, "total_tokens": 246}
}