Images API
API易提供全面的图像处理能力,涵盖图像生成、编辑、理解等多个方面。支持 OpenAI DALL-E、Flux、Sora Image、GPT-Image-1 等多个顶级模型,为您提供最具性价比的图像处理解决方案。
🎯 图像处理能力概览
文生图 通过文字描述生成高质量图像,支持多种风格和尺寸
图像理解 分析理解图片内容,支持对象识别、OCR和场景描述
💰 价格一览
超值推荐 :GPT-4o Image 和 Sora Image 仅需 $0.01/张 ,是目前市场上最具性价比的选择!
模型 文生图价格 图像编辑价格 特点 GPT-4o Image $0.01/张 $0.01/张 💥 价格屠夫,质量优秀 Sora Image $0.01/张 $0.01/张 🚀 极速生成,中文友好 DALL-E 3 $0.04/张 - 🎨 OpenAI官方,细节丰富 DALL-E 2 $0.02/张 $0.02/张 📸 经典模型,稳定可靠 Flux Pro $0.035/张 - 🌟 专业级质量 Flux Max $0.07/张 $0.07/张 👑 最高质量,支持编辑 GPT-Image-1 按Token计费 按Token计费 🔧 灵活控制,功能全面
🚀 文生图 API
标准接口格式
所有文生图模型均使用统一的 OpenAI Images API 格式:
接口地址 :POST https://api.apiyi.com/v1/images/generations
curl https://api.apiyi.com/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4o-image",
"prompt": "A serene Japanese garden with cherry blossoms",
"n": 1,
"size": "1024x1024"
}'
模型详细介绍
🔥 GPT-4o Image(推荐)
价格屠夫 :仅 $0.01/张,同等质量下价格最低!
优势 :极致性价比、质量优秀、生成速度快
支持尺寸 :1024x1024, 1024x1792, 1792x1024
适用场景 :批量生成、日常使用、商业项目
🚀 Sora Image
通过逆向技术实现的高性价比方案:
# Sora Image 使用 Chat Completions API
response = client.chat.completions.create(
model = "gpt-4o" ,
messages = [{
"role" : "user" ,
"content" : "画一幅美丽的日落海景【3:2】" # 在末尾指定比例
}]
)
# 从返回的 markdown 中提取图片 URL
import re
content = response.choices[ 0 ].message.content
image_url = re.search( r '! \[ . *? \]\( ( . *? ) \) ' , content).group( 1 )
价格 :$0.01/张(固定价格)
支持比例 :【2:3】、【3:2】、【1:1】
特点 :中文原生支持、秒级生成
🎨 DALL-E 系列
OpenAI 官方模型,适合追求细节和创意的场景:
# DALL-E 3 - 最新版本,理解能力强
response = client.images.generate(
model = "dall-e-3" ,
prompt = "A detailed oil painting of a robot playing chess" ,
size = "1024x1024" ,
quality = "hd" ,
style = "vivid"
)
# DALL-E 2 - 经典版本,性价比高
response = client.images.generate(
model = "dall-e-2" ,
prompt = "A minimalist logo design for a tech company" ,
size = "512x512"
)
🌟 Flux 系列
专业级图像生成,支持灵活的宽高比:
# Flux Pro - 专业质量
response = client.images.generate(
model = "black-forest-labs/flux-pro-v1.1" ,
prompt = "Professional product photography of a luxury watch" ,
extra_body = {
"aspect_ratio" : "16:9" , # 灵活宽高比
"seed" : 42 , # 可重现结果
"prompt_upsampling" : True # 自动增强提示词
}
)
# Flux Max - 最高质量,支持编辑
response = client.images.generate(
model = "black-forest-labs/flux-kontext-max" ,
prompt = "Ultra detailed fantasy landscape with dragons" ,
extra_body = {
"aspect_ratio" : "21:9" , # 超宽屏
"safety_tolerance" : 2
}
)
Flux 生成的图片 URL 仅 10 分钟有效,请及时下载保存!
🎨 图像编辑 API
OpenAI 标准编辑接口
适用于 DALL-E 2 和 GPT-Image-1:
# 使用遮罩进行局部编辑
response = client.images.edit(
image = open ( "original.png" , "rb" ),
mask = open ( "mask.png" , "rb" ), # 白色=编辑区域
prompt = "A sunflower in the vase" ,
model = "dall-e-2" ,
n = 1 ,
size = "1024x1024"
)
Flux 图像编辑
支持更灵活的编辑控制:
# Flux Max 编辑 - 支持在线图片
response = client.images.edit(
image = "https://example.com/original.jpg" , # 支持URL
mask = "https://example.com/mask.png" , # 可选
prompt = "Transform the car into a futuristic hovering vehicle" ,
model = "black-forest-labs/flux-kontext-max" ,
extra_body = {
"aspect_ratio" : "16:9"
}
)
Sora Image 编辑
通过 Chat API 实现图像编辑和多图融合:
# 单图编辑
response = client.chat.completions.create(
model = "gpt-4o" ,
messages = [{
"role" : "user" ,
"content" : [
{ "type" : "text" , "text" : "将这张图片变成水彩画风格" },
{ "type" : "image_url" , "image_url" : { "url" : "https://example.com/photo.jpg" }}
]
}]
)
# 多图融合
response = client.chat.completions.create(
model = "gpt-4o" ,
messages = [{
"role" : "user" ,
"content" : [
{ "type" : "text" , "text" : "将这两张图片的风格和内容融合" },
{ "type" : "image_url" , "image_url" : { "url" : "https://example.com/style.jpg" }},
{ "type" : "image_url" , "image_url" : { "url" : "https://example.com/content.jpg" }}
]
}]
)
👁️ 图像理解 API
使用 Chat Completions API 分析和理解图片内容:
# 基础图像分析
response = client.chat.completions.create(
model = "gpt-4o" , # 或 gemini-2.5-pro、claude-3-5-sonnet
messages = [{
"role" : "user" ,
"content" : [
{ "type" : "text" , "text" : "请详细描述这张图片的内容" },
{ "type" : "image_url" , "image_url" : { "url" : "https://example.com/image.jpg" }}
]
}]
)
# OCR 文字识别
response = client.chat.completions.create(
model = "gpt-4o" ,
messages = [{
"role" : "user" ,
"content" : [
{ "type" : "text" , "text" : "请提取图片中的所有文字" },
{ "type" : "image_url" , "image_url" : { "url" : "data:image/jpeg;base64,..." }}
]
}]
)
# 多图对比分析
response = client.chat.completions.create(
model = "gemini-2.5-pro" ,
messages = [{
"role" : "user" ,
"content" : [
{ "type" : "text" , "text" : "比较这两张图片的差异" },
{ "type" : "image_url" , "image_url" : { "url" : "image1.jpg" }},
{ "type" : "image_url" , "image_url" : { "url" : "image2.jpg" }}
]
}]
)
推荐模型对比
模型 优势 适用场景 GPT-4o 综合能力强、速度快 通用分析、OCR Gemini 2.5 Pro 2M上下文、细节识别 复杂文档、多图分析 Claude 3.5 Sonnet 逻辑推理强 图表分析、技术图纸
🎯 选择指南
按预算选择
超低预算 推荐 :Sora Image、GPT-4o Image固定 $0.01/张,适合大批量使用
平衡选择 推荐 :DALL-E 2、Flux Pro$0.02-0.035/张,质量与价格平衡
追求品质 推荐 :DALL-E 3、Flux Max$0.04-0.07/张,专业级输出
按用途选择
使用场景 推荐模型 原因 电商产品图 GPT-4o Image 性价比高,质量稳定 艺术创作 DALL-E 3、Flux Max 创意理解强,细节丰富 批量生成 Sora Image 价格最低,速度快 社交媒体 Flux Pro 风格多样,比例灵活 图片编辑 Flux Max、Sora Edit 编辑能力强,支持多图 内容分析 GPT-4o、Gemini 2.5 理解准确,中文友好
💡 最佳实践
1. 提示词优化
[主体描述] + [艺术风格] + [环境设置] + [光照效果] + [质量修饰词]
示例: A majestic eagle (主体) in photorealistic style (风格)
soaring above mountain peaks (环境) during golden hour (光照)
highly detailed, 8K resolution (质量)
英文提示词 :所有模型都支持,表达更精确
中文提示词 :Sora Image 原生支持,其他模型也能理解但效果可能略差
建议 :专业场景用英文,日常使用可用中文
2. 批量处理示例
import asyncio
from openai import AsyncOpenAI
client = AsyncOpenAI(
api_key = "YOUR_API_KEY" ,
base_url = "https://api.apiyi.com/v1"
)
async def generate_batch_images ( prompts ):
tasks = []
for prompt in prompts:
task = client.images.generate(
model = "dall-e-3" ,
prompt = prompt,
n = 1
)
tasks.append(task)
results = await asyncio.gather( * tasks)
return [r.data[ 0 ].url for r in results]
# 使用示例
prompts = [
"A cute cat playing with yarn" ,
"A dog running in the park" ,
"A bird sitting on a branch"
]
urls = await generate_batch_images(prompts)
3. 图片下载保存
部分模型(如 Flux)生成的 URL 有时效性,建议立即下载保存!
import requests
from datetime import datetime
def download_and_save ( image_url , prefix = "image" ):
response = requests.get(image_url)
timestamp = datetime.now().strftime( "%Y%m %d _%H%M%S" )
filename = f " { prefix } _ { timestamp } .png"
with open (filename, 'wb' ) as f:
f.write(response.content)
return filename
# 生成并保存(标准API)
response = client.images.generate(
model = "flux-pro-v1.1" ,
prompt = "Beautiful sunset"
)
saved_file = download_and_save(response.data[ 0 ].url, "sunset" )
print ( f "Image saved as: { saved_file } " )
# 生成并保存(逆向API - GPT-4o Image/Sora Image)
import re
response = client.chat.completions.create(
model = "gpt-4o" ,
messages = [{ "role" : "user" , "content" : "生成美丽的日落图片" }]
)
content = response.choices[ 0 ].message.content
image_url = re.search( r '! \[ . *? \]\( ( . *? ) \) ' , content).group( 1 )
saved_file = download_and_save(image_url, "sunset" )
print ( f "Image saved as: { saved_file } " )
🔧 错误处理
常见错误码
错误码 说明 解决方案 400 参数错误或内容违规 检查参数格式和提示词内容 401 API Key 无效 验证 API Key 是否正确 429 请求频率过高 降低请求频率,使用队列 500 服务器错误 稍后重试或联系支持
内容政策
请避免生成以下内容:
❌ 暴力、血腥内容
❌ 成人、色情内容
❌ 政治敏感内容
❌ 侵犯版权内容
❌ 涉及真实人物的不当内容
📊 使用统计
通过 API易控制台可以查看:
各模型使用量统计
每日/每月生成数量
费用明细和趋势
API 调用日志