DeepSeek API
  1. API 文档
DeepSeek API
  • 快速开始
    • 首次调用 API
    • 模型 & 价格
    • Temperature 设置
    • Token 用量计算
    • 限速
    • 错误码
  • API 文档
    • 基本信息
    • 对话补全
      POST
    • FIM 补全(Beta)
      POST
    • 列出模型
      GET
    • 查询余额
      GET
  • API 指南
    • 推理模型 (deepseek-reasoner)
    • 多轮对话
    • 对话前缀续写(Beta)
    • FIM 补全(Beta)
    • JSON Output
    • Function Calling
    • 上下文硬盘缓存
  • 提示库
    • 代码改写
    • 代码解释
    • 代码生成
    • 内容分类
    • 结构化输出
    • 角色扮演(自定义人设)
    • 角色扮演(情景续写)
    • 散文写作
    • 诗歌创作
    • 文案大纲生成
    • 宣传标语生成
    • 模型提示词生成
    • 中英翻译专家
  • 常见问题
    • 常见问题
  1. API 文档

对话补全

POST
https://api.deepseek.com/chat/completions
根据输入的上下文,来让模型补全对话内容。
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://api.deepseek.com/chat/completions' \
--header 'Authorization: Bearer ' \
--header 'Content-Type: application/json' \
--data-raw '{
  "messages": [
    {
      "content": "You are a helpful assistant",
      "role": "system"
    },
    {
      "content": "你是谁?",
      "role": "user"
    }
  ],
  "model": "deepseek-chat",
  "frequency_penalty": 0,
  "max_tokens": 2048,
  "presence_penalty": 0,
  "response_format": {
    "type": "text"
  },
  "stop": null,
  "stream": false,
  "stream_options": null,
  "temperature": 1,
  "top_p": 1,
  "tools": null,
  "tool_choice": "none",
  "logprobs": false,
  "top_logprobs": null
}'
响应示例响应示例
200 - No streaming - 成功示例
{
  "id": "e137bb42-7580-4cb8-88ba-825209cf966b",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I assist you today? 😊"
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "created": 1739112811,
  "model": "deepseek-chat",
  "system_fingerprint": "fp_3a5790e1b4",
  "object": "chat.completion",
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 11,
    "total_tokens": 20,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "prompt_cache_hit_tokens": 0,
    "prompt_cache_miss_tokens": 9
  }
}

请求参数

Authorization
在 Header 添加参数
Authorization
,其值为在 Bearer 之后拼接 Token
示例:
Authorization: Bearer ********************
Header 参数
Content-Type
string 
必需
示例值:
application/json
Authorization
string 
必需
示例值:
Bearer {{API_KEY}}
Body 参数application/json
messages
array [oneOf] 
对话的消息列表
必需
>= 1 items
object 
System message
可选
object 
User message
可选
object 
Assistant message
可选
object 
Tool message
可选
model
enum<string> 
使用的 AI 模型
必需
枚举值:
deepseek-chatdeepseek-reasoner
frequency_penalty
number  | null 
可选
max_tokens
integer  | null 
可选
presence_penalty
number  | null 
可选
response_format
object  | null 
可选
type
string  | null 
可选
stop
可选
One of
stream
boolean  | null 
是否启用流式传输
可选
stream_options
object  | null 
可选
include_usage
boolean 
可选
temperature
number  | null 
可选
top_p
number  | null 
可选
tools
null 
可选
tool_choice
可选
One of
logprobs
boolean  | null 
可选
top_logprobs
integer  | null 
可选
示例

返回响应

🟢200No streaming
application/json
OK, 返回一个 chat completion 对象。
Body
id
string 
必需
choices
array [object {4}] 
必需
finish_reason
string 
可选
index
integer 
可选
message
object 
可选
logprobs
object  | null 
必需
created
integer 
必需
model
string 
必需
system_fingerprint
string 
必需
object
string 
必需
usage
object 
可选
completion_tokens
integer 
必需
prompt_tokens
integer 
必需
prompt_cache_hit_tokens
integer 
必需
prompt_cache_miss_tokens
integer 
必需
total_tokens
integer 
必需
completion_tokens_details
object 
可选
🟢200Streaming
上一页
基本信息
下一页
FIM 补全(Beta)
Built with