返回模型调用 API 参考POST/v1/chat/completions
DeepSeek:思考聊天与流式返回
以当前公开目录中的 DeepSeek V4.1 Flash 或 V4 Pro 作为 Chat 示例,读取思考与最终答案。
功能与适用场景
适合推理、代码分析和方案比较。thinking 开关是该模型的扩展,不应推断所有 Chat 模型都接受。
支持模型与组合
示例 deepseek-v4.1-flash;deepseek-v4-pro 也在当前公开目录中。模型列表中可能有其他版本或日期别名,先核对准确 ID,不把旧 deepseek-v3-1-250821 当作当前默认。思考字段是否可用仍取决于该模型和上游渠道,不能从名称推断。
第一步:设置鉴权
使用青云TOP API 的 API Key:Authorization: Bearer YOUR_API_KEY。替换占位符,保留 Bearer 后的空格。无需厂商 API Key。
第二步:调用模型
POST https://top.qingyuntop.ai/v1/chat/completions
请求为 application/json。
Chat Completions 兼容协议
调用与返回说明
适合已经依赖 Chat Completions 的客户端和模型。新建 OpenAI 集成时优先确认模型支持 Responses API,再决定是否使用此兼容协议。
请求时注意
- model 和 messages 是基本必填项;tools、tool_choice、response_format 等能力参数按场景发送,不是所有模型都支持。
- 模型 ID 以 GET /v1/models 的返回为准。示例中的固定模型名只是格式示例,不代表当前账号一定可用。
- 对于新推理模型,优先使用 max_completion_tokens;max_tokens 是旧字段,且可能与推理模型不兼容。
返回时注意
- 非流式文本读取 choices[0].message.content,并检查 choices[0].finish_reason。
- 流式读取 choices[].delta.content,收到 finish_reason 后结束;如需用量,在请求中确认服务支持 stream_options.include_usage。
- Chat Completions 的工具调用位于 choices[].message.tool_calls,不能与 Responses 的 output[].type=function_call 混读。
Request
请求
/v1/chat/completionsBody
必填路径、查询与 Header 参数
| 参数 | 位置 | 类型 | 必填 | 说明 | 示例 |
|---|
Content-Type | Header | string | 是 | - | application/json |
Accept | Header | string | 是 | - | application/json |
Authorization | Header | string | 是 | 必填。使用青云TOP API 的 API Key,保留 Bearer 后的空格。 | Bearer YOUR_API_KEY |
X-Forwarded-Host | Header | string | 否 | - | localhost:5173 |
Chat Completions 兼容协议
调用与返回说明
适合已经依赖 Chat Completions 的客户端和模型。新建 OpenAI 集成时优先确认模型支持 Responses API,再决定是否使用此兼容协议。
请求时注意
- model 和 messages 是基本必填项;tools、tool_choice、response_format 等能力参数按场景发送,不是所有模型都支持。
- 模型 ID 以 GET /v1/models 的返回为准。示例中的固定模型名只是格式示例,不代表当前账号一定可用。
- 对于新推理模型,优先使用 max_completion_tokens;max_tokens 是旧字段,且可能与推理模型不兼容。
返回时注意
- 非流式文本读取 choices[0].message.content,并检查 choices[0].finish_reason。
- 流式读取 choices[].delta.content,收到 finish_reason 后结束;如需用量,在请求中确认服务支持 stream_options.include_usage。
- Chat Completions 的工具调用位于 choices[].message.tool_calls,不能与 Responses 的 output[].type=function_call 混读。
常见错误与参考
思考模式下不要依赖 temperature 改变采样效果。后续工具调用需遵循该模型的历史要求,不能任意丢弃 reasoning_content。
401:检查本站 API Key 和 Bearer 格式;403:确认此 Key 可用该模型;429:遵循 Retry-After 退避。超时或 5xx 时保留请求标识和脱敏错误,避免盲目重发;其他通用排查见聊天接入总览。
DeepSeek Chat API。
流式事件示例
下面只展示事件形状。生产客户端应按事件类型处理增量、完成、失败和未完成事件,并设置读取超时。
data: {"id":"chatcmpl_example","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"你好"},"finish_reason":null}]}
data: {"id":"chatcmpl_example","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]