GPT-Image-2 图像生成
gpt-image-2 可通过 OpenAI 兼容图像接口进行文生图和图像编辑。该模型使用 size 同时控制尺寸和画幅比例,不支持 aspect_ratio。
Endpoint
POST /v1/images/generations
POST /v1/images/edits
文生图使用 /v1/images/generations。包含参考图的编辑请求使用 /v1/images/edits。
Authentication
Authorization: Bearer sk-***
Content-Type: application/json
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 固定使用 gpt-image-2。 |
prompt | string | 是 | 图片生成或编辑提示词。 |
image | string/object | 条件必填 | 编辑图片时的参考图。 |
images | array | 条件必填 | 支持多图时使用的参考图数组。 |
size | string | 是 | 输出尺寸,必须使用支持的尺寸值。 |
quality | string | 否 | low、medium 或 high。默认 medium。 |
output_format | string | 否 | png、jpeg 或 webp。 |
n | integer | 否 | 输出图片数量,默认 1,范围为 1 到 8。 |
response_format | string | 否 | 生成资产建议使用 url。 |
支持尺寸
常用尺寸:
| 尺寸 | 比例 | 档位 |
|---|---|---|
1024x768 | 4:3 | 1K |
768x1024 | 3:4 | 1K |
1024x1024 | 1:1 | 1K |
1536x864 | 16:9 | 1K |
864x1536 | 9:16 | 1K |
1920x1080 | 16:9 | 2K |
1080x1920 | 9:16 | 2K |
1536x1536 | 1:1 | 2K |
2048x2048 | 1:1 | 4K |
3840x2160 | 16:9 | 4K |
2160x3840 | 9:16 | 4K |
完整启用尺寸矩阵以产品模型配置为准。
文生图示例
curl -X POST "{BASE_URL}/v1/images/generations" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A small blue glass sphere on a clean white desk, minimal product photo, soft daylight",
"size": "1024x768",
"quality": "low",
"output_format": "webp",
"n": 1,
"response_format": "url"
}'
图像编辑示例
curl -X POST "{BASE_URL}/v1/images/edits" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Keep the product shape, change the background to a bright studio scene",
"image": "https://example.com/input.png",
"size": "1024x1024",
"quality": "medium",
"output_format": "png",
"n": 1,
"response_format": "url"
}'
响应示例
{
"created": 1778688000,
"data": [
{
"url": "https://example.com/generated.png"
}
]
}
计费说明
gpt-image-2 使用 size + quality 参数矩阵计费,并乘以 n。output_format 控制文件格式,在当前来源范围内不是独立计费维度。
常见错误
- 缺少
size。 - 传入
aspect_ratio;该模型应使用size。 quality不在low、medium、high范围内。n不在1到8范围内。- 使用了当前账号不支持的尺寸。