gpt-image-2。
核心能力
- 文生图 - 根据自然语言提示词生成图片
- 图片编辑 - 使用提示词修改上传图片
- 输出控制 - 配置尺寸与质量
- Images API - 使用 /v1/images/generations
输出规格
| 属性 | 取值 |
|---|---|
| 端点 | /v1/images/generations, /v1/images/edits |
| 常用尺寸 | 1024x1024, 1536x1024, 1024x1536, 2048x2048, up to 3840px |
| 尺寸限制 | 边长为 16 的倍数;宽高比不超过 3:1;总像素 655,360-8,294,400 |
| 质量 | low, medium, high, auto |
| 格式 | png, jpeg, webp |
| 背景 | opaque, auto |
快速示例
- cURL
- Python
curl "https://api.mixroute.ai/v1/images/generations" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A minimal red circle centered on a white background",
"size": "1024x1024",
"n": 1,
"quality": "low"
}'
import requests
response = requests.post(
"https://api.mixroute.ai/v1/images/generations",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={'model': 'gpt-image-2',
'prompt': 'A minimal red circle centered on a white background',
'size': '1024x1024',
'n': 1,
'quality': 'low'},
)
print(response.json())
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 固定为 gpt-image-2。 |
prompt | string | 是 | 需要生成图片的文字描述。 |
n | integer | 否 | 生成图片数量。 |
size | string | 否 | 输出图片尺寸。 |
quality | string | 否 | 模型支持时设置输出质量。 |
output_format | string | 否 | png、jpeg 或 webp。 |
output_compression | integer | 否 | JPEG 或 WebP 压缩级别,范围 0-100。 |
background | string | 否 | opaque 或 auto。 |
图片编辑
- cURL
- Python
curl "https://api.mixroute.ai/v1/images/edits" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=gpt-image-2" \
-F "image=@source.png" \
-F "prompt=Replace the white background with a pale blue background" \
-F "size=1024x1024" \
-F "quality=low"
from openai import OpenAI
client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.mixroute.ai/v1")
result = client.images.edit(
model="gpt-image-2",
image=open("source.png", "rb"),
prompt="Replace the white background with a pale blue background",
size="1024x1024",
quality="low",
)
print(result.data[0])
编辑参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
image | file | 是 | 通过 multipart form data 上传的源图片。 |
model | string | 是 | 固定为 gpt-image-2。 |
prompt | string | 是 | 图片编辑指令。 |
size | string | 否 | 输出图片尺寸。 |
quality | string | 否 | 输出质量。 |
output_format | string | 否 | png、jpeg 或 webp。 |
output_compression | integer | 否 | JPEG 或 WebP 压缩级别,范围 0-100。 |