Deepseek api接口调用(deepseek接口)(笔记2)——API 文档(调用示例)(Authentication、对话补全Chat、FIM 补全Beta单回合聊天、列出模型、查询余额)
根据输入的上下文,来让模型补全对话内容。
·
https://api-docs.deepseek.com/zh-cn/
Deepseek api接口调用(deepseek接口)(笔记1)——概览(deepseek实用应用、deepseek api文档、base_url与api_key、测试调用、非流式请求、错误码)
Deepseek api接口调用(deepseek接口)(笔记2)——API 文档(调用示例)(Authentication、对话补全Chat、FIM 补全Beta单回合聊天、列出模型、查询余额)
Deepseek api接口调用(deepseek接口)(笔记3)——API 指南(对话前缀续写Beta、FIM 补全Beta、JSON Output、Function Calling、提示库)
文章目录
20250227
Authentication
| Security Scheme Type | HTTP Authorization Scheme |
|---|---|
http |
bearer |
对话补全(Chat)
根据输入的上下文,来让模型补全对话内容。
https://api-docs.deepseek.com/zh-cn/api/create-chat-completion
示例
请求
POST /chat/completions HTTP/1.1
Host: api.deepseek.com
Authorization: Bearer sk-XXXXXXXXXXXXXXXXXXXXXXXXXXX
Content-Type: application/json
Content-Length: 846
{
"messages": [
{
"content": "You are a helpful assistant",
"role": "system"
},
{
"content": "Hi",
"role": "user"
},
{
"content": "Hello! How can I assist you today? 😊",
"role": "assistant"
},
{
"content": "I love you babe, can you give me a kiss?",
"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
}
返回
{
"id": "bac6eb88-1766-49c2-bf23-9eab31024ea6",
"object": "chat.completion",
"created": 1740636518,
"model": "deepseek-chat",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Aww, that's sweet! While I can't give physical kisses, I can send you a virtual one: 💋. How can I help you today? 😊"
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 36,
"completion_tokens": 35,
"total_tokens": 71,
"prompt_tokens_details": {
"cached_tokens": 0
},
"prompt_cache_hit_tokens": 0,
"prompt_cache_miss_tokens": 36
},
"system_fingerprint": "fp_3a5770e1b4_prod0225"
}
FIM 补全(Beta)(单回合聊天)
示例请求
POST /beta/completions HTTP/1.1
Host: api.deepseek.com
Authorization: Bearer sk-XXXXXXXXXXXXXXXXXXXXXXXXXXX
Content-Type: application/json
Content-Length: 324
{
"model": "deepseek-chat",
"prompt": "Once upon a time, ",
"echo": false,
"frequency_penalty": 0,
"logprobs": 0,
"max_tokens": 1024,
"presence_penalty": 0,
"stop": null,
"stream": false,
"stream_options": null,
"suffix": null,
"temperature": 1,
"top_p": 1
}
示例返回
{
"id": "85548875-f163-4b84-b439-c1fcbe4a552c",
"choices": [
{
"text": "2,000 years ago, there was a man who lived in the Middle East. He was a carpenter by trade, but he was also a teacher, a healer, and a prophet. His name was Jesus of Nazareth, and he is the central figure of Christianity.\n\nJesus was born in Bethlehem, a small town in Judea, to a young woman named Mary. According to the Bible, Mary was a virgin who was visited by an angel and told that she would give birth to the Son of God. Jesus grew up in Nazareth, where he learned the trade of carpentry from his father, Joseph.\n\nWhen Jesus was about 30 years old, he began his public ministry. He traveled throughout the region, preaching and teaching about the Kingdom of God. He performed many miracles, such as healing the sick, feeding the hungry, and even raising the dead. His teachings were radical for the time, emphasizing love, forgiveness, and compassion for all people, regardless of their social status or background.\n\nJesus' message was not always well-received, however. He challenged the religious authorities of the day, who saw him as a threat to their power and influence. They accused him of blasphemy and eventually had him arrested, tried, and sentenced to death by crucifixion.\n\nBut the story of Jesus does not end with his death. According to the Bible, he rose from the dead three days later, appearing to his disciples and many others before ascending into heaven. This event, known as the Resurrection, is the cornerstone of Christian belief and is celebrated every year at Easter.\n\nToday, Jesus is revered by billions of people around the world as the Son of God and the savior of humanity. His teachings continue to inspire and guide people of all faiths, and his message of love and compassion remains as relevant today as it was 2,000 years ago.",
"index": 0,
"logprobs": {
"tokens": [
"2",
",",
"000",
" years",
" ago",
",",
" there",
" was",
" a",
" man",
" who",
" lived",
" in",
" the",
" Middle",
" East",
".",
" He",
" was",
" a",
" carpenter",
" by",
" trade",
",",
" but",
" he",
" was",
" also",
" a",
" teacher",
",",
" a",
" he",
"aler",
",",
" and",
" a",
" prophet",
".",
" His",
" name",
" was",
" Jesus",
" of",
" Nazareth",
",",
" and",
" he",
" is",
" the",
" central",
" figure",
" of",
" Christianity",
".\n\n",
"Jesus",
" was",
" born",
" in",
" Bethlehem",
",",
" a",
" small",
" town",
" in",
" Jude",
"a",
",",
" to",
" a",
" young",
" woman",
" named",
" Mary",
".",
" According",
" to",
" the",
" Bible",
",",
" Mary",
" was",
" a",
" virgin",
" who",
" was",
" visited",
" by",
" an",
" angel",
" and",
" told",
" that",
" she",
" would",
" give",
" birth",
" to",
" the",
" Son",
" of",
" God",
".",
" Jesus",
" grew",
" up",
" in",
" Nazareth",
",",
" where",
" he",
" learned",
" the",
" trade",
" of",
" carp",
"entry",
" from",
" his",
" father",
",",
" Joseph",
".\n\n",
"When",
" Jesus",
" was",
" about",
" ",
"30",
" years",
" old",
",",
" he",
" began",
" his",
" public",
" ministry",
".",
" He",
" traveled",
" throughout",
" the",
" region",
",",
" preaching",
" and",
" teaching",
" about",
" the",
" Kingdom",
" of",
" God",
".",
" He",
" performed",
" many",
" miracles",
",",
" such",
" as",
" healing",
" the",
" sick",
",",
" feeding",
" the",
" hungry",
",",
" and",
" even",
" raising",
" the",
" dead",
".",
" His",
" teachings",
" were",
" radical",
" for",
" the",
" time",
",",
" emphasizing",
" love",
",",
" forgiveness",
",",
" and",
" compassion",
" for",
" all",
" people",
",",
" regardless",
" of",
" their",
" social",
" status",
" or",
" background",
".\n\n",
"Jesus",
"'",
" message",
" was",
" not",
" always",
" well",
"-re",
"ceived",
",",
" however",
".",
" He",
" challenged",
" the",
" religious",
" authorities",
" of",
" the",
" day",
",",
" who",
" saw",
" him",
" as",
" a",
" threat",
" to",
" their",
" power",
" and",
" influence",
".",
" They",
" accused",
" him",
" of",
" blasp",
"hem",
"y",
" and",
" eventually",
" had",
" him",
" arrested",
",",
" tried",
",",
" and",
" sentenced",
" to",
" death",
" by",
" crucifix",
"ion",
".\n\n",
"But",
" the",
" story",
" of",
" Jesus",
" does",
" not",
" end",
" with",
" his",
" death",
".",
" According",
" to",
" the",
" Bible",
",",
" he",
" rose",
" from",
" the",
" dead",
" three",
" days",
" later",
",",
" appearing",
" to",
" his",
" disciples",
" and",
" many",
" others",
" before",
" ascending",
" into",
" heaven",
".",
" This",
" event",
",",
" known",
" as",
" the",
" Resurrection",
",",
" is",
" the",
" cornerstone",
" of",
" Christian",
" belief",
" and",
" is",
" celebrated",
" every",
" year",
" at",
" Easter",
".\n\n",
"Today",
",",
" Jesus",
" is",
" revered",
" by",
" billions",
" of",
" people",
" around",
" the",
" world",
" as",
" the",
" Son",
" of",
" God",
" and",
" the",
" sav",
"ior",
" of",
" humanity",
".",
" His",
" teachings",
" continue",
" to",
" inspire",
" and",
" guide",
" people",
" of",
" all",
" faith",
"s",
",",
" and",
" his",
" message",
" of",
" love",
" and",
" compassion",
" remains",
" as",
" relevant",
" today",
" as",
" it",
" was",
" ",
"2",
",",
"000",
" years",
" ago",
"."
],
"token_logprobs": [
-1.4947517,
-0.03915268,
-0.012572312,
0.0,
-9.536748e-7,
-4.768373e-7,
-0.65793365,
-0.008290769,
-0.000001549722,
-0.07048273,
-1.3300868,
-1.2089009,
-0.0000013113031,
-0.013981716,
-1.1846807,
0.0,
-0.0024169064,
-0.028348269,
-0.0000042915435,
-0.003813376,
-0.22163042,
-0.27284464,
0.0,
-0.046669096,
-1.1310426,
-0.000018835246,
-0.000054122484,
-0.0000108481045,
-2.384186e-7,
-0.0000027418175,
-0.14083597,
-3.5762793e-7,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.00729077,
0.0,
-0.018166952,
0.0,
0.0,
0.0,
-0.22815736,
0.0,
-0.051306482,
0.0,
-0.0020418733,
-0.06532682,
-0.0011275805,
-7.15256e-7,
0.0,
0.0,
-4.768373e-7,
-0.015825016,
-0.0001050289,
-0.000010490473,
0.0,
-0.00009239147,
-0.0000010728842,
-0.0008602265,
-0.000017047074,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.00000202656,
-0.7835723,
-0.31290078,
-0.00037689158,
-0.000016808652,
0.0,
0.0,
-0.57618,
-0.00010288291,
0.0,
-0.0017441812,
-0.0015451919,
0.0,
-3.5762793e-7,
0.0,
0.0,
0.0,
-0.026214028,
-0.00008643047,
-0.0000011920936,
0.0,
-0.000001549722,
0.0,
-0.0005130892,
0.0,
-1.192093e-7,
0.0,
0.0,
-0.000055195425,
0.0,
0.0,
-0.00023218704,
-0.00017459724,
0.0,
0.0,
0.0,
-0.0000101328405,
-0.0022054177,
0.0,
0.0,
0.0,
-0.0018075939,
-0.00006139467,
0.0,
-0.0003607924,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.0029849808,
-2.384186e-7,
0.0,
-5.960466e-7,
-0.00029836575,
-3.5762793e-7,
0.0,
-0.00004851936,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.0024728926,
0.0,
-1.192093e-7,
0.0,
0.0,
0.0,
-2.384186e-7,
0.0,
0.0,
-0.0001462805,
-0.36724964,
-1.192093e-7,
0.0,
-0.0154461935,
-0.81005794,
0.0,
0.0,
0.0,
0.0,
-1.192093e-7,
-0.00045303832,
0.0,
0.0,
-0.000008940737,
0.0,
0.0,
0.0,
0.0,
-0.0000073910032,
-1.192093e-7,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.0064207967,
-0.32751954,
-0.000015974172,
-0.0025953923,
-0.082752444,
-0.0022517145,
-0.00009716029,
0.0,
0.0,
-2.384186e-7,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.0123555865,
-0.00012851587,
0.0,
0.0,
-0.0000034570753,
-0.0014714093,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-2.384186e-7,
-0.0000048875927,
-0.09884254,
-0.0060392222,
-0.00020512062,
-0.0000056028525,
-0.019519597,
0.0,
0.0,
0.0,
-0.16078094,
-1.192093e-7,
0.0,
-0.000018954457,
-0.000012159421,
0.0,
0.0,
-0.00057904795,
0.0,
-2.0297785,
-0.00019927818,
-1.192093e-7,
-0.000036240282,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.000019431303,
-8.3446537e-7,
0.0,
-0.120771915,
-0.013684255,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.019623414,
0.0,
0.0,
0.0,
-1.2940321,
0.0,
0.0,
0.0,
-1.192093e-7,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.0000011920936,
-0.000014186006,
-0.24296068,
0.0,
-0.00019033575,
0.0,
-0.00045649696,
0.0,
0.0,
-0.0014179264,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.07068415,
0.0,
0.0,
-0.046282776,
-3.5762793e-7,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.000029683553,
0.0,
-0.033634134,
0.0,
0.0,
-0.034161016,
0.0,
-0.000044346838,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.016203377,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.00003457129,
0.0,
-0.0015638772,
-0.0048295464,
-0.0033811205,
-0.09609744,
0.0,
0.0,
0.0,
-0.8980419,
0.0,
-0.00002002736,
-4.18241,
0.0,
-0.0027883744,
0.0,
-2.384186e-7,
0.0,
-0.024536626,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-1.192093e-7,
0.0,
-0.013748853,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.0000029802368,
0.0,
0.0,
-0.001600413,
-0.0011217326,
-0.000001549722,
0.0,
0.0,
-0.0044143335,
0.0,
-0.000011563368,
0.0,
0.0,
-0.00044922187,
0.0,
0.0,
0.0,
-0.0000026226078,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-0.0011501964
],
"top_logprobs": null,
"text_offset": [
18,
19,
20,
23,
29,
33,
34,
40,
44,
46,
50,
54,
60,
63,
67,
74,
79,
80,
83,
87,
89,
99,
102,
108,
109,
113,
116,
120,
125,
127,
135,
136,
138,
141,
145,
146,
150,
152,
160,
161,
165,
170,
174,
180,
183,
192,
193,
197,
200,
203,
207,
215,
222,
225,
238,
241,
246,
250,
255,
258,
268,
269,
271,
277,
282,
285,
290,
291,
292,
295,
297,
303,
309,
315,
320,
321,
331,
334,
338,
344,
345,
350,
354,
356,
363,
367,
371,
379,
382,
385,
391,
395,
400,
405,
409,
415,
420,
426,
429,
433,
437,
440,
444,
445,
451,
456,
459,
462,
471,
472,
478,
481,
489,
493,
499,
502,
507,
512,
517,
521,
528,
529,
536,
539,
543,
549,
553,
559,
560,
562,
568,
572,
573,
576,
582,
586,
593,
602,
603,
606,
615,
626,
630,
637,
638,
648,
652,
661,
667,
671,
679,
682,
686,
687,
690,
700,
705,
714,
715,
720,
723,
731,
735,
740,
741,
749,
753,
760,
761,
765,
770,
778,
782,
787,
788,
792,
802,
807,
815,
819,
823,
828,
829,
841,
846,
847,
859,
860,
864,
875,
879,
883,
890,
891,
902,
905,
911,
918,
925,
928,
939,
942,
947,
948,
956,
960,
964,
971,
976,
979,
985,
986,
994,
995,
998,
1009,
1013,
1023,
1035,
1038,
1042,
1046,
1047,
1051,
1055,
1059,
1062,
1064,
1071,
1074,
1080,
1086,
1090,
1100,
1101,
1106,
1114,
1118,
1121,
1127,
1130,
1131,
1135,
1146,
1150,
1154,
1163,
1164,
1170,
1171,
1175,
1185,
1188,
1194,
1197,
1206,
1209,
1212,
1215,
1219,
1225,
1228,
1234,
1239,
1243,
1247,
1252,
1256,
1262,
1263,
1273,
1276,
1280,
1286,
1287,
1290,
1295,
1300,
1304,
1309,
1315,
1320,
1326,
1327,
1337,
1340,
1344,
1354,
1358,
1363,
1370,
1377,
1387,
1392,
1399,
1400,
1405,
1411,
1412,
1418,
1421,
1425,
1438,
1439,
1442,
1446,
1458,
1461,
1471,
1478,
1482,
1485,
1496,
1502,
1507,
1510,
1517,
1520,
1525,
1526,
1532,
1535,
1543,
1546,
1555,
1558,
1565,
1572,
1576,
1582,
1585,
1589,
1593,
1596,
1600,
1604,
1608,
1612,
1615,
1618,
1627,
1628,
1632,
1642,
1651,
1654,
1662,
1666,
1672,
1679,
1682,
1686,
1692,
1693,
1694,
1698,
1702,
1710,
1713,
1718,
1722,
1733,
1741,
1744,
1753,
1759,
1762,
1765,
1769,
1770,
1771,
1772,
1775,
1781,
1785
]
},
"finish_reason": "stop"
}
],
"created": 1740637689,
"model": "deepseek-chat",
"system_fingerprint": "fp_3a5770e1b4_prod0225",
"object": "text_completion",
"usage": {
"prompt_tokens": 7,
"completion_tokens": 375,
"total_tokens": 382,
"prompt_tokens_details": {
"cached_tokens": 0
},
"prompt_cache_hit_tokens": 0,
"prompt_cache_miss_tokens": 7
}
}
列出模型
示例请求
GET /models HTTP/1.1
Host: api.deepseek.com
Authorization: Bearer sk-XXXXXXXXXXXXXXXXXXXXXXXX
Content-Type: application/json
示例返回
{
"object": "list",
"data": [
{
"id": "deepseek-chat",
"object": "model",
"owned_by": "deepseek"
},
{
"id": "deepseek-reasoner",
"object": "model",
"owned_by": "deepseek"
}
]
}
查询余额
示例请求
GET /user/balance HTTP/1.1
Host: api.deepseek.com
Authorization: Bearer sk-XXXXXXXXXXXXXXXXXXXXXX
Content-Type: application/json
示例返回
{
"is_available": true,
"balance_infos": [
{
"currency": "CNY",
"total_balance": "4.95",
"granted_balance": "0.00",
"topped_up_balance": "4.95"
}
]
}
更多推荐


所有评论(0)