API易 提供强大的图像理解能力,支持使用多种先进的 AI 模型对图像进行深度分析和理解。通过统一的 OpenAI API 格式,您可以轻松实现图像识别、场景描述、OCR 文字识别等功能。
🔍 智能视觉分析
支持对象识别、场景理解、文字提取、情感分析等多种视觉任务,让 AI 真正”看懂”图片。
🌟 核心特性
- 🎯 多模型支持:Gemini 3 系列、GPT-5 系列、Claude 4 系列等顶级多模态模型
- 📸 灵活输入:支持 URL 链接和 Base64 编码图片
- 🌏 中文优化:完美支持中文场景理解和文字识别
- ⚡ 快速响应:高性能推理,秒级返回结果
- 💰 成本可控:多种模型选择,满足不同预算需求
📋 支持的视觉模型
以下为当前主流的多模态模型推荐,模型 ID 可能随版本更新,请以控制台为准。
| 模型名称 | 模型 ID | 特点 | 推荐场景 |
|---|
| Gemini 3.1 Pro Preview ⭐ | gemini-3.1-pro-preview | 最强多模态推理,细节丰富 | 复杂图像/场景分析 |
| Gemini 3.5 Flash 🔥 | gemini-3.5-flash | 速度快、价格低,性价比之王 | 实时识图、批量处理 |
| GPT-5.5 ⭐ | gpt-5.5 | 综合视觉理解强,稳定可靠 | 通用图像理解 |
| Claude Opus 4.7 | claude-opus-4-7 | 理解深入,描述精准 | 专业图文分析 |
| Claude Sonnet 4.6 | claude-sonnet-4-6 | 性能媲美 Opus,性价比高 | 高性价比识图 |
| GPT-4o | gpt-4o | 经典多模态,成熟稳定 | 通用场景 |
| Gemini 2.5 Flash | gemini-2.5-flash | 超快超便宜,正式版 | 大批量简单识图 |
绝大多数对话模型现已支持多模态识图:上表仅为常用推荐,并非全部。GPT-5 系列、Gemini 3 系列、Claude 4 系列、Grok 4、Qwen、GLM、Kimi 等主流模型大多已支持图像输入。
🚀 快速开始
1. 基础示例 - 图片 URL
import requests
url = "https://api.apiyi.com/v1/chat/completions"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
payload = {
"model": "gpt-5.5",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "请详细描述这张图片的内容"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg"
}
}
]
}
]
}
response = requests.post(url, headers=headers, json=payload)
result = response.json()
print(result['choices'][0]['message']['content'])
2. 本地图片示例 - Base64 编码
import base64
import requests
def image_to_base64(image_path):
"""将本地图片转换为 base64 编码"""
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
# 读取本地图片
base64_image = image_to_base64("path/to/your/image.jpg")
url = "https://api.apiyi.com/v1/chat/completions"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
payload = {
"model": "gemini-3.1-pro-preview",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "分析这张图片中的所有文字内容"
},
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{base64_image}"
}
}
]
}
]
}
response = requests.post(url, headers=headers, json=payload)
print(response.json()['choices'][0]['message']['content'])
3. 高级示例 - 多图对比分析
import requests
url = "https://api.apiyi.com/v1/chat/completions"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
payload = {
"model": "gemini-3.1-pro-preview",
"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"}
}
]
}
],
"max_tokens": 1000
}
response = requests.post(url, headers=headers, json=payload)
print(response.json()['choices'][0]['message']['content'])
4. cURL 示例(命令行)
图片 URL 方式:
curl https://api.apiyi.com/v1/chat/completions \
-H "Authorization: Bearer $APIYI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-pro-preview",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "请详细描述这张图片的内容" },
{ "type": "image_url", "image_url": { "url": "https://example.com/image.jpg" } }
]
}
]
}'
本地图片 Base64 方式(先把图片编码成 Base64 再拼进请求体):
# 1. 将本地图片转为 base64(macOS / Linux)
BASE64_IMAGE=$(base64 -i path/to/your/image.jpg | tr -d '\n')
# 2. 通过 data URI 传入图片内容
curl https://api.apiyi.com/v1/chat/completions \
-H "Authorization: Bearer $APIYI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.5",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "分析这张图片中的所有文字内容" },
{ "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,'"$BASE64_IMAGE"'" } }
]
}
]
}'
Base64 体积约为原图的 1.33 倍,大图建议优先用图片 URL 方式以减小请求体、加快响应。
GPT-5 系列参数差异:若把示例中的模型换成 gpt-5.5 / gpt-5.4 等 GPT-5 系列,请注意:
- 用
max_completion_tokens 替代 max_tokens
temperature 只支持 1(默认即可,不要传其它值)
- 不要传
top_p 参数
Gemini、Claude 系列则无此限制,可正常使用 max_tokens、temperature 等参数。
🎯 常见应用场景
1. 商品识别与分析
prompt = """
请分析这张商品图片,包括:
1. 商品类型和品牌
2. 主要特征和卖点
3. 适合的目标用户
4. 建议的营销文案
"""
2. 文档 OCR 识别
prompt = """
请提取图片中的所有文字内容,并按照原始格式整理输出。
如果有表格,请用 Markdown 表格格式呈现。
"""
3. 医学影像辅助分析
prompt = """
这是一张医学影像图片,请:
1. 描述图像的基本信息(如成像类型、部位等)
2. 标注可见的解剖结构
3. 注意:仅供参考,不作为诊断依据
"""
4. 安全监控场景分析
prompt = """
分析监控画面,识别:
1. 场景中的人数和位置
2. 是否有异常行为
3. 环境安全隐患
4. 时间戳信息(如果可见)
"""
💡 最佳实践
图片预处理建议
- 格式支持:JPEG、PNG、GIF、WebP 等主流格式
- 大小限制:建议单张图片不超过 20MB
- 分辨率:高分辨率图片会获得更好的识别效果
- 压缩优化:适度压缩以提高传输速度
提示词优化
# ❌ 不推荐:模糊的提示
prompt = "看看这是什么"
# ✅ 推荐:具体明确的提示
prompt = """
请从以下几个方面分析这张图片:
1. 主要对象:识别图片中的主要物体或人物
2. 场景环境:描述拍摄地点和环境特征
3. 色彩构图:分析配色方案和构图特点
4. 情感氛围:图片传达的情绪或氛围
5. 可能用途:这张图片适合用于什么场景
"""
错误处理
import requests
from requests.exceptions import RequestException
def analyze_image_with_retry(image_url, prompt, max_retries=3):
"""带重试机制的图像分析函数"""
for attempt in range(max_retries):
try:
response = requests.post(
"https://api.apiyi.com/v1/chat/completions",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
},
json={
"model": "gpt-5.5",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": prompt},
{"type": "image_url", "image_url": {"url": image_url}}
]
}]
},
timeout=30
)
if response.status_code == 200:
return response.json()
elif response.status_code == 429:
print(f"速率限制,等待后重试... (尝试 {attempt + 1}/{max_retries})")
time.sleep(2 ** attempt) # 指数退避
else:
print(f"错误: {response.status_code} - {response.text}")
except RequestException as e:
print(f"请求异常: {e}")
return None
🔧 高级功能
1. 流式输出
对于长篇分析,可以使用流式输出获得更好的用户体验:
payload = {
"model": "gpt-5.5",
"messages": [...],
"stream": True
}
response = requests.post(url, headers=headers, json=payload, stream=True)
for line in response.iter_lines():
if line:
print(line.decode('utf-8'))
2. 多轮对话
保持上下文进行深入分析:
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": "这是什么动物?"},
{"type": "image_url", "image_url": {"url": "animal.jpg"}}
]
},
{
"role": "assistant",
"content": "这是一只金毛寻回犬。"
},
{
"role": "user",
"content": [{"type": "text", "text": "它看起来多大了?健康状况如何?"}]
}
]
3. 结合函数调用
tools = [
{
"type": "function",
"function": {
"name": "save_image_analysis",
"description": "保存图像分析结果到数据库",
"parameters": {
"type": "object",
"properties": {
"objects": {"type": "array", "items": {"type": "string"}},
"scene": {"type": "string"},
"text_content": {"type": "string"}
}
}
}
}
]
payload = {
"model": "gpt-5.5",
"messages": messages,
"tools": tools,
"tool_choice": "auto"
}
📊 性能对比
| 模型 | 响应速度 | 识别准确度 | 中文支持 | 价格 |
|---|
| Gemini 3.1 Pro Preview | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | $$ |
| Gemini 3.5 Flash | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | $ |
| GPT-5.5 | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | $$ |
| Claude Sonnet 4.6 | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | $$ |
| Gemini 2.5 Flash | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | $ |
🚨 注意事项
- 隐私保护:不要上传包含敏感信息的图片
- 合规使用:遵守相关法律法规,不用于非法用途
- 结果验证:AI 分析结果仅供参考,重要决策需人工复核
- 成本控制:合理选择模型,避免不必要的开销
🔗 相关资源
💡 小贴士:建议先使用 Gemini 3.5 Flash 或 Gemini 2.5 Flash 等高性价比模型进行测试,确认效果后再切换到 Gemini 3.1 Pro、GPT-5.5 等高级模型进行生产部署。更多可用模型请查看 当下热门模型 或 控制台模型列表。