返回模型调用 API 参考POST/v1/chat/completions
Chat:图片 URL 与流式识图
使用 image_url 内容块传入图片,正确区分 URL 与 Base64 输入。
功能与适用场景
发送一张公网图片,逐段接收识图结果。
支持模型与组合
示例 gpt-4.1。只选择支持图像输入的型号;文本专用模型和 Embedding 模型不能识图。
第一步:设置鉴权
使用青云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 |
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 混读。
常见错误与参考
小字号、旋转、模糊图片会降低识别准确度。先裁剪重点区域并保留清晰度;涉及精确数值时人工复核。
401:检查本站 API Key 和 Bearer 格式;403:确认此 Key 可用该模型;429:遵循 Retry-After 退避。超时或 5xx 时保留请求标识和脱敏错误,避免盲目重发;其他通用排查见聊天接入总览。
OpenAI 公共 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]