DeepSeek API
快速开始
首次调用 API
模型 & 价格
Temperature 设置
Token 用量计算
限速
错误码
API文档
基本信息
对话补全
POST
FIM 补全(Beta)
POST
列出模型
GET
查询余额
GET
API指南
推理模型 (deepseek-reasoner)
多轮对话
对话前缀续写(Beta)
FIM 补全(Beta)
JSON Output
Function Calling
上下文硬盘缓存
提示库
代码改写
代码解释
代码生成
内容分类
结构化输出
角色扮演(自定义人设)
角色扮演(情景续写)
散文写作
诗歌创作
文案大纲生成
宣传标语生成
模型提示词生成
中英翻译专家
常见问题
对话补全开发中
POSThttps://api.deepseek.com/chat/completions
创建时间: 2025-05-29 17:51
请求参数
Header 参数
参数名示例值是否必填参数类型描述说明
AuthorizationBearer {{API_KEY}}string-
Body 参数application/json
数据结构
messagesarray<oneOf>
必填
对话的消息列表
0object
可选
contentstring
必填
system 消息的内容
rolestring
必填
该消息的发起角色,其值为 `system`
namestring
可选
可以选填的参与者的名称,为模型提供信息以区分相同角色的参与者
1object
可选
contentstring
必填
user 消息的内容
rolestring
必填
该消息的发起角色,其值为 `user`
namestring
可选
可以选填的参与者的名称,为模型提供信息以区分相同角色的参与者
2object
可选
contentstring
必填
assistant 消息的内容
rolestring
必填
该消息的发起角色,其值为 `assistant`
namestring
可选
可以选填的参与者的名称,为模型提供信息以区分相同角色的参与者。
3object
可选
rolestring
必填
该消息的发起角色,其值为 `tool`
contentstring
必填
tool 消息的内容
tool_call_idstring
必填
此消息所响应的 tool call 的 ID
modelstring
必填
使用的 AI 模型
frequency_penaltynumber
可选
max_tokensinteger
可选
presence_penaltynumber
可选
response_formatobject
可选
typestring
可选
stop
可选
streamboolean
可选
是否启用流式传输
stream_optionsobject
可选
include_usageboolean
可选
temperaturenumber
可选
top_pnumber
可选
toolsnull
可选
tool_choice
可选
logprobsboolean
可选
top_logprobsinteger
可选
示例数据
{
  "messages": [
    {
      "content": "You are a helpful assistant",
      "role": "system"
    },
    {
      "content": "Hi",
      "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
}
响应示例
成功(No Steaming)
HTTP状态码:200
内容格式:JSON
数据结构
idstring
必填
choicesarray<object>
必填
finish_reasonstring
可选
indexinteger
可选
messageobject
可选
contentstring
必填
reasoning_contentstring
可选
tool_callsarray<object>
可选
idstring
可选
typestring
可选
functionobject
可选
namestring
必填
argumentsstring
必填
rolestring
必填
logprobsobject
必填
contentarray<object>
必填
tokenstring
必填
logprobnumber
必填
bytesarray<integer>
必填
top_logprobsarray<object>
必填
tokenstring
可选
logprobinteger
可选
bytesarray<integer>
可选
createdinteger
必填
modelstring
必填
system_fingerprintstring
必填
objectstring
必填
usageobject
可选
completion_tokensinteger
必填
prompt_tokensinteger
必填
prompt_cache_hit_tokensinteger
必填
prompt_cache_miss_tokensinteger
必填
total_tokensinteger
必填
completion_tokens_detailsobject
可选
reasoning_tokensinteger
必填
响应示例
{
  "id": "abc389feca",
  "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
  }
}
成功(Streaming)
HTTP状态码:200
内容格式:Event-Stream
数据结构
未定义
响应示例
data: {
    "id": "1",
    "choices": [
        {
            "index": 0,
            "delta": {
                "content": "",
                "role": "assistant"
            },
            "finish_reason": null,
            "logprobs": null
        }
    ],
    "created": 1718347123,
    "model": "deepseek-chat",
    "system_fingerprint": "fp_a49d71b8a1",
    "object": "chat.completion.chunk",
    "usage": null
}

data: {
    "choices": [
        {
            "delta": {
                "content": "Hello",
                "role": "assistant"
            },
            "finish_reason": null,
            "index": 0,
            "logprobs": null
        }
    ],
    "created": 1718347123,
    "id": "12cb5aed",
    "model": "deepseek-chat",
    "object": "chat.completion.chunk",
    "system_fingerprint": "fp_a49d71b8a1"
}

data: {
    "choices": [
        {
            "delta": {
                "content": "!",
                "role": "assistant"
            },
            "finish_reason": null,
            "index": 0,
            "logprobs": null
        }
    ],
    "created": 1718347123,
    "id": "12cb5aed",
    "model": "deepseek-chat",
    "object": "chat.completion.chunk",
    "system_fingerprint": "fp_a49d71b8a1"
}

data: {
    "choices": [
        {
            "delta": {
                "content": " How",
                "role": "assistant"
            },
            "finish_reason": null,
            "index": 0,
            "logprobs": null
        }
    ],
    "created": 1718347123,
    "id": "12cb5aed",
    "model": "deepseek-chat",
    "object": "chat.completion.chunk",
    "system_fingerprint": "fp_a49d71b8a1"
}

data: {
    "choices": [
        {
            "delta": {
                "content": " can",
                "role": "assistant"
            },
            "finish_reason": null,
            "index": 0,
            "logprobs": null
        }
    ],
    "created": 1718347123,
    "id": "12cb5aed",
    "model": "deepseek-chat",
    "object": "chat.completion.chunk",
    "system_fingerprint": "fp_a49d71b8a1"
}

data: {
    "choices": [
        {
            "delta": {
                "content": " I",
                "role": "assistant"
            },
            "finish_reason": null,
            "index": 0,
            "logprobs": null
        }
    ],
    "created": 1718347123,
    "id": "12cb5aed",
    "model": "deepseek-chat",
    "object": "chat.completion.chunk",
    "system_fingerprint": "fp_a49d71b8a1"
}

data: {
    "choices": [
        {
            "delta": {
                "content": " assist",
                "role": "assistant"
            },
            "finish_reason": null,
            "index": 0,
            "logprobs": null
        }
    ],
    "created": 1718347123,
    "id": "12cb5aed",
    "model": "deepseek-chat",
    "object": "chat.completion.chunk",
    "system_fingerprint": "fp_a49d71b8a1"
}

data: {
    "choices": [
        {
            "delta": {
                "content": " you",
                "role": "assistant"
            },
            "finish_reason": null,
            "index": 0,
            "logprobs": null
        }
    ],
    "created": 1718347123,
    "id": "12cb5aed",
    "model": "deepseek-chat",
    "object": "chat.completion.chunk",
    "system_fingerprint": "fp_a49d71b8a1"
}

data: {
    "choices": [
        {
            "delta": {
                "content": " today",
                "role": "assistant"
            },
            "finish_reason": null,
            "index": 0,
            "logprobs": null
        }
    ],
    "created": 1718347123,
    "id": "12cb5aed",
    "model": "deepseek-chat",
    "object": "chat.completion.chunk",
    "system_fingerprint": "fp_a49d71b8a1"
}

data: {
    "choices": [
        {
            "delta": {
                "content": "?",
                "role": "assistant"
            },
            "finish_reason": null,
            "index": 0,
            "logprobs": null
        }
    ],
    "created": 1718347123,
    "id": "12cb5aed",
    "model": "deepseek-chat",
    "object": "chat.completion.chunk",
    "system_fingerprint": "fp_a49d71b8a1"
}

data: {
    "choices": [
        {
            "delta": {
                "content": "",
                "role": null
            },
            "finish_reason": "stop",
            "index": 0,
            "logprobs": null
        }
    ],
    "created": 1718347123,
    "id": "12cb5aed",
    "model": "deepseek-chat",
    "object": "chat.completion.chunk",
    "system_fingerprint": "fp_a49d71b8a1",
    "usage": {
        "completion_tokens": 9,
        "prompt_tokens": 17,
        "total_tokens": 26
    }
}

data: [DONE
]
最后更新: 2 个月前