Features
视觉支持
多模态 AI 视觉 API - 向 GPT-4 Vision、Claude 3、Gemini Pro 发送图像。图像分析、OCR、图表理解,支持 URL 或 base64 输入。
视觉支持
UniterRouter 支持可以分析和描述图像的视觉模型。你可以通过 HTTPS URL 或内联 base64 编码数据提供图像。
支持视觉的模型
你可以在我们的带视觉筛选的模型页面找到所有支持视觉的模型。这些模型可以在同一请求中处理文本和图像内容。
图像格式
使用 HTTPS URL
你可以提供任何公开可访问的指向图像的 HTTPS URL:
curl -X POST "https://api.uniterouter.ai/v1/chat/completions" \
-H "Authorization: Bearer $UNITEROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "你在这张图片中看到了什么?"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg"
}
}
]
}
]
}'使用 Base64 内联数据
你也可以以 base64 编码的数据 URI 形式提供图像:
curl -X POST "https://api.uniterouter.ai/v1/chat/completions" \
-H "Authorization: Bearer $UNITEROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "描述这张图片"
},
{
"type": "image_url",
"image_url": {
"url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD..."
}
}
]
}
]
}'内容数组格式
使用视觉模型时,content 字段应该是一个包含文本和图像内容块的数组:
- 文本内容:
{"type": "text", "text": "你的消息"} - 图像内容:
{"type": "image_url", "image_url": {"url": "图像_url_或_数据_uri"}}
多张图像
你可以在单个请求中包含多张图像:
curl -X POST "https://api.uniterouter.ai/v1/chat/completions" \
-H "Authorization: Bearer $UNITEROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "比较这两张图片"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image1.jpg"
}
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image2.jpg"
}
}
]
}
]
}'简单字符串内容
对于视觉模型,你仍然可以对纯文本消息使用简单字符串内容。数组格式仅在包含图像时需要。
curl -X POST "https://api.uniterouter.ai/v1/chat/completions" \
-H "Authorization: Bearer $UNITEROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "你好!你今天能帮我什么?"
}
]
}'支持的图像类型
视觉模型通常支持常见的图像格式,包括:
- JPEG (.jpg, .jpeg)
- PNG (.png)
- WebP (.webp)
- GIF (.gif)
支持的具体格式可能因模型提供商而异。查看各个模型文档了解格式限制和文件大小限制。
错误处理
如果图像 URL 无法访问或图像格式不支持,网关会优雅地处理错误,可能会在发送给底层模型的请求中替换为占位符或错误消息。
How is this guide?