创建聊天识图 (流式)
POST/v1/chat/completions 创建聊天识图(流式)
POST https://www.vortapapi.com/v1/chat/completions
通过聊天补全接口提交包含图片与文本的对话消息,模型会根据输入内容生成回复。启用流式输出时,服务端会以增量事件的形式持续返回生成结果,适合需要边生成边展示的场景。
请求头
| 名称 | 必填 | 说明 |
|---|---|---|
Content-Type | 是 | 请求体格式,通常为 application/json |
Accept | 是 | 使用流式响应时建议设置为 text/event-stream |
Authorization | 否 | API Key 鉴权,格式为 Bearer sk-*** |
请求示例
curl https://www.vortapapi.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-H "Authorization: Bearer sk-***" \
-d '{
"model": "claude-3-5-sonnet",
"stream": true,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "请描述这张图片中的内容。"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg"
}
}
]
}
]
}'
响应示例
非流式响应示例:
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}
流式响应会按事件逐步返回内容片段,直到生成结束。