aicodeswitch 3.9.3 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,799 @@
1
+ Title: 对话补全 | DeepSeek API Docs
2
+
3
+ URL Source: https://api-docs.deepseek.com/zh-cn/api/create-chat-completion
4
+
5
+ Published Time: Fri, 13 Feb 2026 13:35:43 GMT
6
+
7
+ Markdown Content:
8
+ 对话补全 | DeepSeek API Docs
9
+ ===============
10
+
11
+ 对话补全
12
+ ====
13
+
14
+ POST
15
+ https://api.deepseek.com/chat/completions
16
+ -----------------------------------------
17
+
18
+ 根据输入的上下文,来让模型补全对话内容。
19
+
20
+ Request[​](https://api-docs.deepseek.com/zh-cn/api/create-chat-completion#request "Request的直接链接")
21
+ -------------------------------------------------------------------------------------------------
22
+
23
+ * application/json
24
+
25
+ ### Body
26
+
27
+ **required**
28
+
29
+ **messages**
30
+ object[]
31
+
32
+ required
33
+
34
+ **Possible values:**`>= 1`
35
+
36
+ 对话的消息列表。
37
+
38
+ * Array [
39
+
40
+ oneOf
41
+
42
+ * System message
43
+ * User message
44
+ * Assistant message
45
+ * Tool message
46
+
47
+ **content** string required
48
+
49
+ system 消息的内容。
50
+
51
+ **role** string required
52
+
53
+ **Possible values:** [`system`]
54
+
55
+ 该消息的发起角色,其值为 `system`。
56
+
57
+ **name** string
58
+
59
+ 可以选填的参与者的名称,为模型提供信息以区分相同角色的参与者。
60
+
61
+ **content** Text content (string)required
62
+
63
+ user 消息的内容。
64
+
65
+ **role** string required
66
+
67
+ **Possible values:** [`user`]
68
+
69
+ 该消息的发起角色,其值为 `user`。
70
+
71
+ **name** string
72
+
73
+ 可以选填的参与者的名称,为模型提供信息以区分相同角色的参与者。
74
+
75
+ **content** string nullable required
76
+
77
+ assistant 消息的内容。
78
+
79
+ **role** string required
80
+
81
+ **Possible values:** [`assistant`]
82
+
83
+ 该消息的发起角色,其值为 `assistant`。
84
+
85
+ **name** string
86
+
87
+ 可以选填的参与者的名称,为模型提供信息以区分相同角色的参与者。
88
+
89
+ **prefix** bool
90
+
91
+ (Beta) 设置此参数为 true,来强制模型在其回答中以此 `assistant` 消息中提供的前缀内容开始。
92
+
93
+ 您必须设置 `base_url="https://api.deepseek.com/beta"` 来使用此功能。
94
+
95
+ **reasoning_content** string nullable
96
+
97
+ (Beta) 用于 `deepseek-reasoner` 模型在[对话前缀续写](https://api-docs.deepseek.com/zh-cn/guides/chat_prefix_completion)功能下,作为最后一条 assistant 思维链内容的输入。使用此功能时,`prefix` 参数必须设置为 `true`。
98
+
99
+ **role** string required
100
+
101
+ **Possible values:** [`tool`]
102
+
103
+ 该消息的发起角色,其值为 `tool`。
104
+
105
+ **content** Text content (string)required
106
+
107
+ tool 消息的内容。
108
+
109
+ **tool_call_id** string required
110
+
111
+ 此消息所响应的 tool call 的 ID。
112
+
113
+ * ]
114
+
115
+ **model** string required
116
+
117
+ **Possible values:** [`deepseek-chat`, `deepseek-reasoner`]
118
+
119
+ 使用的模型的 ID。您可以使用 deepseek-chat。
120
+
121
+ **thinking**
122
+ object
123
+
124
+ nullable
125
+
126
+ 控制思考模式与非思考模式的转换
127
+
128
+ **type** string
129
+
130
+ **Possible values:** [`enabled`, `disabled`]
131
+
132
+ 如果设为 `enabled`,则使用思考模式。如果设为 `disabled`,则使用非思考模式
133
+
134
+ **frequency_penalty** number nullable
135
+
136
+ **Possible values:**`>= -2` and `<= 2`
137
+
138
+ **Default value:**`0`
139
+
140
+ 介于 -2.0 和 2.0 之间的数字。如果该值为正,那么新 token 会根据其在已有文本中的出现频率受到相应的惩罚,降低模型重复相同内容的可能性。
141
+
142
+ **max_tokens** integer nullable
143
+
144
+ 限制一次请求中模型生成 completion 的最大 token 数。输入 token 和输出 token 的总长度受模型的上下文长度的限制。取值范围与默认值详见[文档](https://api-docs.deepseek.com/zh-cn/quick_start/pricing)。
145
+
146
+ **presence_penalty** number nullable
147
+
148
+ **Possible values:**`>= -2` and `<= 2`
149
+
150
+ **Default value:**`0`
151
+
152
+ 介于 -2.0 和 2.0 之间的数字。如果该值为正,那么新 token 会根据其是否已在已有文本中出现受到相应的惩罚,从而增加模型谈论新主题的可能性。
153
+
154
+ **response_format**
155
+ object
156
+
157
+ nullable
158
+
159
+ 一个 object,指定模型必须输出的格式。
160
+
161
+ 设置为 { "type": "json_object" } 以启用 JSON 模式,该模式保证模型生成的消息是有效的 JSON。
162
+
163
+ **注意:** 使用 JSON 模式时,你还必须通过系统或用户消息指示模型生成 JSON。否则,模型可能会生成不断的空白字符,直到生成达到令牌限制,从而导致请求长时间运行并显得“卡住”。此外,如果 finish_reason="length",这表示生成超过了 max_tokens 或对话超过了最大上下文长度,消息内容可能会被部分截断。
164
+
165
+ **type** string
166
+
167
+ **Possible values:** [`text`, `json_object`]
168
+
169
+ **Default value:**`text`
170
+
171
+ Must be one of `text` or `json_object`.
172
+
173
+ **stop**
174
+ object
175
+
176
+ **nullable**
177
+
178
+ 一个 string 或最多包含 16 个 string 的 list,在遇到这些词时,API 将停止生成更多的 token。
179
+
180
+ oneOf
181
+
182
+ * MOD1
183
+ * MOD2
184
+
185
+ string
186
+
187
+ * Array [
188
+
189
+ string
190
+
191
+ * ]
192
+
193
+ **stream** boolean nullable
194
+
195
+ 如果设置为 True,将会以 SSE(server-sent events)的形式以流式发送消息增量。消息流以 `data: [DONE]` 结尾。
196
+
197
+ **stream_options**
198
+ object
199
+
200
+ nullable
201
+
202
+ 流式输出相关选项。只有在 `stream` 参数为 `true` 时,才可设置此参数。
203
+
204
+ **include_usage** boolean
205
+
206
+ 如果设置为 true,在流式消息最后的 `data: [DONE]` 之前将会传输一个额外的块。此块上的 usage 字段显示整个请求的 token 使用统计信息,而 choices 字段将始终是一个空数组。所有其他块也将包含一个 usage 字段,但其值为 null。
207
+
208
+ **temperature** number nullable
209
+
210
+ **Possible values:**`<= 2`
211
+
212
+ **Default value:**`1`
213
+
214
+ 采样温度,介于 0 和 2 之间。更高的值,如 0.8,会使输出更随机,而更低的值,如 0.2,会使其更加集中和确定。 我们通常建议可以更改这个值或者更改 `top_p`,但不建议同时对两者进行修改。
215
+
216
+ **top_p** number nullable
217
+
218
+ **Possible values:**`<= 1`
219
+
220
+ **Default value:**`1`
221
+
222
+ 作为调节采样温度的替代方案,模型会考虑前 `top_p` 概率的 token 的结果。所以 0.1 就意味着只有包括在最高 10% 概率中的 token 会被考虑。 我们通常建议修改这个值或者更改 `temperature`,但不建议同时对两者进行修改。
223
+
224
+ **tools**
225
+ object[]
226
+
227
+ nullable
228
+
229
+ 模型可能会调用的 tool 的列表。目前,仅支持 function 作为工具。使用此参数来提供以 JSON 作为输入参数的 function 列表。最多支持 128 个 function。
230
+
231
+ * Array [
232
+
233
+ **type** string required
234
+
235
+ **Possible values:** [`function`]
236
+
237
+ tool 的类型。目前仅支持 function。
238
+
239
+ **function**
240
+ object
241
+
242
+ required
243
+
244
+ **description** string
245
+
246
+ function 的功能描述,供模型理解何时以及如何调用该 function。
247
+
248
+ **name** string required
249
+
250
+ 要调用的 function 名称。必须由 a-z、A-Z、0-9 字符组成,或包含下划线和连字符,最大长度为 64 个字符。
251
+
252
+ **parameters**
253
+ object
254
+
255
+ function 的输入参数,以 JSON Schema 对象描述。请参阅[Tool Calls 指南](https://api-docs.deepseek.com/zh-cn/guides/tool_calls)获取示例,并参阅[JSON Schema 参考](https://json-schema.org/understanding-json-schema/)了解有关格式的文档。省略 `parameters` 会定义一个参数列表为空的 function。
256
+
257
+ **property name*** any
258
+
259
+ function 的输入参数,以 JSON Schema 对象描述。请参阅[Tool Calls 指南](https://api-docs.deepseek.com/zh-cn/guides/tool_calls)获取示例,并参阅[JSON Schema 参考](https://json-schema.org/understanding-json-schema/)了解有关格式的文档。省略 `parameters` 会定义一个参数列表为空的 function。
260
+
261
+ **strict** boolean
262
+
263
+ **Default value:**`false`
264
+
265
+ 如果设置为 true,API 将在函数调用中使用 strict 模式,以确保输出始终符合函数的 JSON schema 定义。该功能为 Beta 功能,详细使用方式请参阅[Tool Calls 指南](https://api-docs.deepseek.com/zh-cn/guides/tool_calls)
266
+
267
+ * ]
268
+
269
+ **tool_choice**
270
+ object
271
+
272
+ **nullable**
273
+
274
+ 控制模型调用 tool 的行为。
275
+
276
+ `none` 意味着模型不会调用任何 tool,而是生成一条消息。
277
+
278
+ `auto` 意味着模型可以选择生成一条消息或调用一个或多个 tool。
279
+
280
+ `required` 意味着模型必须调用一个或多个 tool。
281
+
282
+ 通过 `{"type": "function", "function": {"name": "my_function"}}` 指定特定 tool,会强制模型调用该 tool。
283
+
284
+ 当没有 tool 时,默认值为 `none`。如果有 tool 存在,默认值为 `auto`。
285
+
286
+ oneOf
287
+
288
+ * ChatCompletionToolChoice
289
+ * ChatCompletionNamedToolChoice
290
+
291
+ string
292
+
293
+ **Possible values:** [`none`, `auto`, `required`]
294
+
295
+ **type** string required
296
+
297
+ **Possible values:** [`function`]
298
+
299
+ tool 的类型。目前,仅支持 `function`。
300
+
301
+ **function**
302
+ object
303
+
304
+ required
305
+
306
+ **name** string required
307
+
308
+ 要调用的函数名称。
309
+
310
+ **logprobs** boolean nullable
311
+
312
+ 是否返回所输出 token 的对数概率。如果为 true,则在 `message` 的 `content` 中返回每个输出 token 的对数概率。
313
+
314
+ **top_logprobs** integer nullable
315
+
316
+ **Possible values:**`<= 20`
317
+
318
+ 一个介于 0 到 20 之间的整数 N,指定每个输出位置返回输出概率 top N 的 token,且返回这些 token 的对数概率。指定此参数时,logprobs 必须为 true。
319
+
320
+ Responses[​](https://api-docs.deepseek.com/zh-cn/api/create-chat-completion#responses "Responses的直接链接")
321
+ -------------------------------------------------------------------------------------------------------
322
+
323
+ * 200 (No streaming)
324
+ * 200 (Streaming)
325
+
326
+ OK, 返回一个 `chat completion` 对象。
327
+
328
+ * application/json
329
+
330
+ * Schema
331
+ * Example (from schema)
332
+ * Example
333
+
334
+ **Schema**
335
+
336
+ **id** string required
337
+
338
+ 该对话的唯一标识符。
339
+
340
+ **choices**
341
+ object[]
342
+
343
+ required
344
+
345
+ 模型生成的 completion 的选择列表。
346
+
347
+ * Array [
348
+
349
+ **finish_reason** string required
350
+
351
+ **Possible values:** [`stop`, `length`, `content_filter`, `tool_calls`, `insufficient_system_resource`]
352
+
353
+ 模型停止生成 token 的原因。
354
+
355
+ `stop`:模型自然停止生成,或遇到 `stop` 序列中列出的字符串。
356
+
357
+ `length` :输出长度达到了模型上下文长度限制,或达到了 `max_tokens` 的限制。
358
+
359
+ `content_filter`:输出内容因触发过滤策略而被过滤。
360
+
361
+ `insufficient_system_resource`:系统推理资源不足,生成被打断。
362
+
363
+ **index** integer required
364
+
365
+ 该 completion 在模型生成的 completion 的选择列表中的索引。
366
+
367
+ **message**
368
+ object
369
+
370
+ required
371
+
372
+ 模型生成的 completion 消息。
373
+
374
+ **content** string nullable required
375
+
376
+ 该 completion 的内容。
377
+
378
+ **reasoning_content** string nullable
379
+
380
+ 仅适用于 deepseek-reasoner 模型。内容为 assistant 消息中在最终答案之前的推理内容。
381
+
382
+ **tool_calls**
383
+ object[]
384
+
385
+ 模型生成的 tool 调用,例如 function 调用。
386
+
387
+ * Array [
388
+
389
+ **id** string required
390
+
391
+ tool 调用的 ID。
392
+
393
+ **type** string required
394
+
395
+ **Possible values:** [`function`]
396
+
397
+ tool 的类型。目前仅支持 `function`。
398
+
399
+ **function**
400
+ object
401
+
402
+ required
403
+
404
+ 模型调用的 function。
405
+
406
+ **name** string required
407
+
408
+ 模型调用的 function 名。
409
+
410
+ **arguments** string required
411
+
412
+ 要调用的 function 的参数,由模型生成,格式为 JSON。请注意,模型并不总是生成有效的 JSON,并且可能会臆造出你函数模式中未定义的参数。在调用函数之前,请在代码中验证这些参数。
413
+
414
+ * ]
415
+
416
+ **role** string required
417
+
418
+ **Possible values:** [`assistant`]
419
+
420
+ 生成这条消息的角色。
421
+
422
+ **logprobs**
423
+ object
424
+
425
+ nullable
426
+
427
+ required
428
+
429
+ 该 choice 的对数概率信息。
430
+
431
+ **content**
432
+ object[]
433
+
434
+ nullable
435
+
436
+ required
437
+
438
+ 一个包含输出 token 对数概率信息的列表。
439
+
440
+ * Array [
441
+
442
+ **token** string required
443
+
444
+ 输出的 token。
445
+
446
+ **logprob** number required
447
+
448
+ 该 token 的对数概率。`-9999.0` 代表该 token 的输出概率极小,不在 top 20 最可能输出的 token 中。
449
+
450
+ **bytes** integer[]nullable required
451
+
452
+ 一个包含该 token UTF-8 字节表示的整数列表。一般在一个 UTF-8 字符被拆分成多个 token 来表示时有用。如果 token 没有对应的字节表示,则该值为 `null`。
453
+
454
+ **top_logprobs**
455
+ object[]
456
+
457
+ required
458
+
459
+ 一个包含在该输出位置上,输出概率 top N 的 token 的列表,以及它们的对数概率。在罕见情况下,返回的 token 数量可能少于请求参数中指定的 `top_logprobs` 值。
460
+
461
+ * Array [
462
+
463
+ **token** string required
464
+
465
+ 输出的 token。
466
+
467
+ **logprob** number required
468
+
469
+ 该 token 的对数概率。`-9999.0` 代表该 token 的输出概率极小,不在 top 20 最可能输出的 token 中。
470
+
471
+ **bytes** integer[]nullable required
472
+
473
+ 一个包含该 token UTF-8 字节表示的整数列表。一般在一个 UTF-8 字符被拆分成多个 token 来表示时有用。如果 token 没有对应的字节表示,则该值为 `null`。
474
+
475
+ * ]
476
+
477
+ * ]
478
+
479
+ **reasoning_content**
480
+ object[]
481
+
482
+ nullable
483
+
484
+ 一个包含输出 token 对数概率信息的列表。
485
+
486
+ * Array [
487
+
488
+ **token** string required
489
+
490
+ 输出的 token。
491
+
492
+ **logprob** number required
493
+
494
+ 该 token 的对数概率。`-9999.0` 代表该 token 的输出概率极小,不在 top 20 最可能输出的 token 中。
495
+
496
+ **bytes** integer[]nullable required
497
+
498
+ 一个包含该 token UTF-8 字节表示的整数列表。一般在一个 UTF-8 字符被拆分成多个 token 来表示时有用。如果 token 没有对应的字节表示,则该值为 `null`。
499
+
500
+ **top_logprobs**
501
+ object[]
502
+
503
+ required
504
+
505
+ 一个包含在该输出位置上,输出概率 top N 的 token 的列表,以及它们的对数概率。在罕见情况下,返回的 token 数量可能少于请求参数中指定的 `top_logprobs` 值。
506
+
507
+ * Array [
508
+
509
+ **token** string required
510
+
511
+ 输出的 token。
512
+
513
+ **logprob** number required
514
+
515
+ 该 token 的对数概率。`-9999.0` 代表该 token 的输出概率极小,不在 top 20 最可能输出的 token 中。
516
+
517
+ **bytes** integer[]nullable required
518
+
519
+ 一个包含该 token UTF-8 字节表示的整数列表。一般在一个 UTF-8 字符被拆分成多个 token 来表示时有用。如果 token 没有对应的字节表示,则该值为 `null`。
520
+
521
+ * ]
522
+
523
+ * ]
524
+
525
+ * ]
526
+
527
+ **created** integer required
528
+
529
+ 创建聊天完成时的 Unix 时间戳(以秒为单位)。
530
+
531
+ **model** string required
532
+
533
+ 生成该 completion 的模型名。
534
+
535
+ **system_fingerprint** string required
536
+
537
+ This fingerprint represents the backend configuration that the model runs with.
538
+
539
+ **object** string required
540
+
541
+ **Possible values:** [`chat.completion`]
542
+
543
+ 对象的类型, 其值为 `chat.completion`。
544
+
545
+ **usage**
546
+ object
547
+
548
+ 该对话补全请求的用量信息。
549
+
550
+ **completion_tokens** integer required
551
+
552
+ 模型 completion 产生的 token 数。
553
+
554
+ **prompt_tokens** integer required
555
+
556
+ 用户 prompt 所包含的 token 数。该值等于 `prompt_cache_hit_tokens + prompt_cache_miss_tokens`
557
+
558
+ **prompt_cache_hit_tokens** integer required
559
+
560
+ 用户 prompt 中,命中上下文缓存的 token 数。
561
+
562
+ **prompt_cache_miss_tokens** integer required
563
+
564
+ 用户 prompt 中,未命中上下文缓存的 token 数。
565
+
566
+ **total_tokens** integer required
567
+
568
+ 该请求中,所有 token 的数量(prompt + completion)。
569
+
570
+ **completion_tokens_details**
571
+ object
572
+
573
+ completion tokens 的详细信息。
574
+
575
+ **reasoning_tokens** integer
576
+
577
+ 推理模型所产生的思维链 token 数量
578
+
579
+ `{ "id": "string", "choices": [ { "finish_reason": "stop", "index": 0, "message": { "content": "string", "reasoning_content": "string", "tool_calls": [ { "id": "string", "type": "function", "function": { "name": "string", "arguments": "string" } } ], "role": "assistant" }, "logprobs": { "content": [ { "token": "string", "logprob": 0, "bytes": [ 0 ], "top_logprobs": [ { "token": "string", "logprob": 0, "bytes": [ 0 ] } ] } ], "reasoning_content": [ { "token": "string", "logprob": 0, "bytes": [ 0 ], "top_logprobs": [ { "token": "string", "logprob": 0, "bytes": [ 0 ] } ] } ] } } ], "created": 0, "model": "string", "system_fingerprint": "string", "object": "chat.completion", "usage": { "completion_tokens": 0, "prompt_tokens": 0, "prompt_cache_hit_tokens": 0, "prompt_cache_miss_tokens": 0, "total_tokens": 0, "completion_tokens_details": { "reasoning_tokens": 0 } }}`
580
+
581
+ `{ "id": "930c60df-bf64-41c9-a88e-3ec75f81e00e", "choices": [ { "finish_reason": "stop", "index": 0, "message": { "content": "Hello! How can I help you today?", "role": "assistant" } } ], "created": 1705651092, "model": "deepseek-chat", "object": "chat.completion", "usage": { "completion_tokens": 10, "prompt_tokens": 16, "total_tokens": 26 }}`
582
+
583
+ OK, 返回包含一系列 `chat completion chunk` 对象的流式输出。
584
+
585
+ * text/event-stream
586
+
587
+ * Schema
588
+ * Example
589
+
590
+ **Schema**
591
+
592
+ * Array [
593
+
594
+ **id** string required
595
+
596
+ 该对话的唯一标识符。
597
+
598
+ **choices**
599
+ object[]
600
+
601
+ required
602
+
603
+ 模型生成的 completion 的选择列表。
604
+
605
+ * Array [
606
+
607
+ **delta**
608
+ object
609
+
610
+ required
611
+
612
+ 流式返回的一个 completion 增量。
613
+
614
+ **content** string nullable
615
+
616
+ completion 增量的内容。
617
+
618
+ **reasoning_content** string nullable
619
+
620
+ 仅适用于 deepseek-reasoner 模型。内容为 assistant 消息中在最终答案之前的推理内容。
621
+
622
+ **role** string
623
+
624
+ **Possible values:** [`assistant`]
625
+
626
+ 产生这条消息的角色。
627
+
628
+ **logprobs**
629
+ object
630
+
631
+ nullable
632
+
633
+ 该 choice 的对数概率信息。
634
+
635
+ **content**
636
+ object[]
637
+
638
+ nullable
639
+
640
+ required
641
+
642
+ 一个包含输出 token 对数概率信息的列表。
643
+
644
+ * Array [
645
+
646
+ **token** string required
647
+
648
+ 输出的 token。
649
+
650
+ **logprob** number required
651
+
652
+ 该 token 的对数概率。`-9999.0` 代表该 token 的输出概率极小,不在 top 20 最可能输出的 token 中。
653
+
654
+ **bytes** integer[]nullable required
655
+
656
+ 一个包含该 token UTF-8 字节表示的整数列表。一般在一个 UTF-8 字符被拆分成多个 token 来表示时有用。如果 token 没有对应的字节表示,则该值为 `null`。
657
+
658
+ **top_logprobs**
659
+ object[]
660
+
661
+ required
662
+
663
+ 一个包含在该输出位置上,输出概率 top N 的 token 的列表,以及它们的对数概率。在罕见情况下,返回的 token 数量可能少于请求参数中指定的 `top_logprobs` 值。
664
+
665
+ * Array [
666
+
667
+ **token** string required
668
+
669
+ 输出的 token。
670
+
671
+ **logprob** number required
672
+
673
+ 该 token 的对数概率。`-9999.0` 代表该 token 的输出概率极小,不在 top 20 最可能输出的 token 中。
674
+
675
+ **bytes** integer[]nullable required
676
+
677
+ 一个包含该 token UTF-8 字节表示的整数列表。一般在一个 UTF-8 字符被拆分成多个 token 来表示时有用。如果 token 没有对应的字节表示,则该值为 `null`。
678
+
679
+ * ]
680
+
681
+ * ]
682
+
683
+ **reasoning_content**
684
+ object[]
685
+
686
+ nullable
687
+
688
+ 一个包含输出 token 对数概率信息的列表。
689
+
690
+ * Array [
691
+
692
+ **token** string required
693
+
694
+ 输出的 token。
695
+
696
+ **logprob** number required
697
+
698
+ 该 token 的对数概率。`-9999.0` 代表该 token 的输出概率极小,不在 top 20 最可能输出的 token 中。
699
+
700
+ **bytes** integer[]nullable required
701
+
702
+ 一个包含该 token UTF-8 字节表示的整数列表。一般在一个 UTF-8 字符被拆分成多个 token 来表示时有用。如果 token 没有对应的字节表示,则该值为 `null`。
703
+
704
+ **top_logprobs**
705
+ object[]
706
+
707
+ required
708
+
709
+ 一个包含在该输出位置上,输出概率 top N 的 token 的列表,以及它们的对数概率。在罕见情况下,返回的 token 数量可能少于请求参数中指定的 `top_logprobs` 值。
710
+
711
+ * Array [
712
+
713
+ **token** string required
714
+
715
+ 输出的 token。
716
+
717
+ **logprob** number required
718
+
719
+ 该 token 的对数概率。`-9999.0` 代表该 token 的输出概率极小,不在 top 20 最可能输出的 token 中。
720
+
721
+ **bytes** integer[]nullable required
722
+
723
+ 一个包含该 token UTF-8 字节表示的整数列表。一般在一个 UTF-8 字符被拆分成多个 token 来表示时有用。如果 token 没有对应的字节表示,则该值为 `null`。
724
+
725
+ * ]
726
+
727
+ * ]
728
+
729
+ **finish_reason** string nullable required
730
+
731
+ **Possible values:** [`stop`, `length`, `content_filter`, `tool_calls`, `insufficient_system_resource`]
732
+
733
+ 模型停止生成 token 的原因。
734
+
735
+ `stop`:模型自然停止生成,或遇到 `stop` 序列中列出的字符串。
736
+
737
+ `length` :输出长度达到了模型上下文长度限制,或达到了 `max_tokens` 的限制。
738
+
739
+ `content_filter`:输出内容因触发过滤策略而被过滤。
740
+
741
+ `insufficient_system_resource`: 由于后端推理资源受限,请求被打断。
742
+
743
+ **index** integer required
744
+
745
+ 该 completion 在模型生成的 completion 的选择列表中的索引。
746
+
747
+ * ]
748
+
749
+ **created** integer required
750
+
751
+ 创建聊天完成时的 Unix 时间戳(以秒为单位)。流式响应的每个 chunk 的时间戳相同。
752
+
753
+ **model** string required
754
+
755
+ 生成该 completion 的模型名。
756
+
757
+ **system_fingerprint** string required
758
+
759
+ This fingerprint represents the backend configuration that the model runs with.
760
+
761
+ **object** string required
762
+
763
+ **Possible values:** [`chat.completion.chunk`]
764
+
765
+ 对象的类型, 其值为 `chat.completion.chunk`。
766
+
767
+ * ]
768
+
769
+ `data: {"id": "1f633d8bfc032625086f14113c411638", "choices": [{"index": 0, "delta": {"content": "", "role": "assistant"}, "finish_reason": null, "logprobs": null}], "created": 1718345013, "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": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "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": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "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": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "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": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "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": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "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": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "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": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "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": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "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": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "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": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "model": "deepseek-chat", "object": "chat.completion.chunk", "system_fingerprint": "fp_a49d71b8a1", "usage": {"completion_tokens": 9, "prompt_tokens": 17, "total_tokens": 26}}data: [DONE]`
770
+
771
+ * curl
772
+ * python
773
+ * go
774
+ * nodejs
775
+ * ruby
776
+ * csharp
777
+ * php
778
+ * java
779
+ * powershell
780
+
781
+ * CURL
782
+
783
+ `curl -L -X POST 'https://api.deepseek.com/chat/completions' \-H 'Content-Type: application/json' \-H 'Accept: application/json' \-H 'Authorization: Bearer <TOKEN>' \--data-raw '{ "messages": [ { "content": "You are a helpful assistant", "role": "system" }, { "content": "Hi", "role": "user" } ], "model": "deepseek-chat", "thinking": { "type": "disabled" }, "frequency_penalty": 0, "max_tokens": 4096, "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}'`
784
+
785
+ Request Collapse all
786
+
787
+ Base URL
788
+
789
+ Edit
790
+
791
+ https://api.deepseek.com
792
+
793
+ Auth
794
+
795
+ Bearer Token
796
+
797
+ Body required
798
+
799
+ { "messages": [ { "content": "You are a helpful assistant", "role": "system" }, { "content": "Hi", "role": "user" } ], "model": "deepseek-chat", "thinking": { "type": "disabled" }, "frequency_penalty": 0, "max_tokens": 4096, "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}