- 文本对话
对话补全
POST
/chat/completions
请求参数
Authorization
在 Header 添加参数
Authorization
,其值为在 Bearer 之后拼接 Token示例:
Authorization: Bearer ********************
Header 参数
Content-Type
string
必需
示例值:
application/json
Body 参数application/json
model
enum<string>
必需
枚举值:
deepseek-ai/DeepSeek-R1
message
array [anyOf]
对话的消息列表
>= 1 items
object
System Message
object
User message
object
Assistant Message
frequency_penalty
number
可选
>= -2<= 2
默认值:
0
max_tokens
integer
可选
>= 1<= 8192
默认值:
512
response_format
object
可选
type
enum<string>
必需
枚举值:
textjson_object
默认值:
text
stop
可选
One of
stream
boolean
可选
data: [DONE]
结尾。stream_options
object
可选
stream
参数为true
时,才可设置此参数。include_usage
boolean
必需
true
,在流式消息最后的data: [DONE]
之前将会传输一个额外的块。此块上的 usage 字段显示整个请求的 token 使用统计信息,而 choices 字段将始终是一个空数组。所有其他块也将包含一个 usage 字段,但其值为null
。temperature
number
可选
top_p
,但不建议同时对两者进行修改。>= 0<= 2
默认值:
1
top_p
number
可选
top_p
概率的 token 的结果。所以 0.1 就意味着只有包括在最高 10% 概率中的 token 会被考虑。 我们通常建议修改这个值或者更改temperature
,但不建议同时对两者进行修改。<= 1> 0
默认值:
1
tool
array [object {2}]
可选
type
enum<string>
必需
枚举值:
function
function
object
必需
tool_choice
可选
none
意味着模型不会调用任何 tool,而是生成一条消息。auto
意味着模型可以选择生成一条消息或调用一个或多个 tool。required
意味着模型必须调用一个或多个 tool。{"type": "function", "function": {"name": "my_function"}}
指定特定 tool,会强制模型调用该 tool。none
。如果有tool
存在,默认值为auto
。One of
none
意味着模型不会调用任何 tool,而是生成一条消息。auto
意味着模型可以选择生成一条消息或调用一个或多个 tool。required
意味着模型必须调用一个或多个 tool。枚举值:
noneautorequired
logprobs
boolean
可选
true
,则在message
的content
中返回每个输出 token 的对数概率。top_logprobs
integer
可选
logprobs
必须为true
。>= 0<= 20
示例
{
"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
}
示例代码
Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://api.damodel.com/chat/completions' \
--header 'Content-Type: application/json' \
--data-raw '{
"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
}'
返回响应
🟢200流式成功
application/json
Body
id
string
该对话的唯一标识符
choices
array [object {3}]
必需
delta
object
必需
finish_reason
enum<string> | enum<null>
必需
stop
:模型自然停止生成,或遇到stop
序列中列出的字符串。length
:输出长度达到了模型上下文长度限制,或达到了max_tokens
的限制。content_filter
:输出内容因触发过滤策略而被过滤。insufficient_system_resource
:系统推理资源不足,生成被打断。枚举值:
stoplenthcontent_filtertool_callsinsufficient_system_resource
index
integer
必需
created
string
必需
model
string
必需
object
enum<string>
必需
枚举值:
chat.completion.chunk
usage
object | null
可选
completion_tokens
integer
必需
prompt_tokens
integer
必需
total_tokens
integer
必需
示例
{
"id": "string",
"choices": [
{
"delta": {
"content": "string",
"reasoning_content": "string",
"role": "assistant"
},
"finish_reason": "stop",
"index": 0
}
],
"created": "string",
"model": "string",
"object": "chat.completion.chunk",
"usage": {
"completion_tokens": 0,
"prompt_tokens": 0,
"total_tokens": 0
}
}
🟢200非流式成功
修改于 2025-03-05 11:06:41