视觉理解(多模态对话)
接口概述
视觉理解与文本生成共用同一个接口 /v1/chat/completions:把 messages[].content 从字符串换成内容数组,放入图片即可。图片支持公网 URL,也支持 Base64。
接口地址
POST https://openai.jw-info.com/v1/chat/completions
请求头
| 请求头 | 是否必填 | 说明 |
|---|---|---|
| Content-Type | 是 | application/json |
| Authorization | 是 | Bearer {API_KEY},或 x-api-key |
请求参数
| 参数名 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 支持视觉理解的模型,广场卡片会标「视觉理解」 |
| messages[].content[].type | string | 是 | text 或 image_url |
| messages[].content[].text | string | 条件必填 | 文本内容(type=text 时) |
| messages[].content[].image_url.url | string | 条件必填 | 图片地址或 data:image/png;base64,... |
| max_tokens | integer | 否 | 最大生成 token 数 |
| temperature | float | 否 | 采样温度 |
请求示例
curl https://openai.jw-info.com/v1/chat/completions \
-H "Authorization: Bearer sk-你的密钥" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.8-max",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "这张图里有什么?"},
{"type": "image_url", "image_url": {"url": "https://example.com/cat.jpg"}}
]
}
]
}'
响应参数
与文本生成一致:choices[0].message.content 为识别结果,usage 给出输入输出 token 数。注意图片也会被折算成输入 token 计费。
响应示例
{
"choices": [
{ "index": 0,
"message": { "role": "assistant", "content": "图里是一只白色的猫,坐在木桌上。" },
"finish_reason": "stop" }
],
"usage": { "prompt_tokens": 812, "completion_tokens": 22, "total_tokens": 834 }
}