创建聊天识图 (非流)
POST/v1/chat/completions 创建聊天识图(非流式)
使用 Chat Completions 接口提交包含图片的对话请求,模型会基于文本与图像内容生成一次性返回的回复。本接口为非流式响应,即完整结果会在请求处理完成后一次性返回。
请求
POST https://www.vortapapi.com/v1/chat/completions
请求头
| 名称 | 必填 | 说明 |
|---|---|---|
Content-Type | 是 | 请求体格式,通常为 application/json |
Accept | 是 | 响应格式,通常为 application/json |
Authorization | 否 | API Key 鉴权,例如:Bearer sk-*** |
请求体说明
该接口兼容 OpenAI Chat Completions 格式。进行图片理解时,可在 messages 中同时传入文本与图片内容。
常用字段包括:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 要调用的模型名称 |
messages | array | 是 | 对话消息列表,可包含文本和图片输入 |
stream | boolean | 否 | 是否使用流式响应。非流式请求请设置为 false 或省略 |
请求示例
{
"model": "claude-3-5-sonnet",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "请描述这张图片中的内容。"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg"
}
}
]
}
],
"stream": false
}
响应示例
{
"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
}
}
响应字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 本次生成结果的唯一标识 |
object | string | 对象类型,通常为 chat.completion |
created | integer | 响应创建时间,Unix 时间戳 |
choices | array | 模型生成的候选回复列表 |
choices[].index | integer | 候选结果序号 |
choices[].message | object | 模型返回的消息内容 |
choices[].message.role | string | 消息角色,通常为 assistant |
choices[].message.content | string | 模型生成的文本回复 |
choices[].finish_reason | string | 生成结束原因,例如 stop |
usage | object | Token 使用统计 |
usage.prompt_tokens | integer | 输入消耗的 token 数 |
usage.completion_tokens | integer | 输出消耗的 token 数 |
usage.total_tokens | integer | 输入与输出合计 token 数 |