跳到主要内容
AI
MarkdownLLMs.txt

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

请求参数

参数类型必填说明
modelstring固定使用 gpt-image-2
promptstring图片生成或编辑提示词。
imagestring/object条件必填编辑图片时的参考图。
imagesarray条件必填支持多图时使用的参考图数组。
sizestring输出尺寸,必须使用支持的尺寸值。
qualitystringlowmediumhigh。默认 medium
output_formatstringpngjpegwebp
ninteger输出图片数量,默认 1,范围为 18
response_formatstring生成资产建议使用 url

支持尺寸

常用尺寸:

尺寸比例档位
1024x7684:31K
768x10243:41K
1024x10241:11K
1536x86416:91K
864x15369:161K
1920x108016:92K
1080x19209:162K
1536x15361:12K
2048x20481:14K
3840x216016:94K
2160x38409:164K

完整启用尺寸矩阵以产品模型配置为准。

文生图示例

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 参数矩阵计费,并乘以 noutput_format 控制文件格式,在当前来源范围内不是独立计费维度。

常见错误

  • 缺少 size
  • 传入 aspect_ratio;该模型应使用 size
  • quality 不在 lowmediumhigh 范围内。
  • n 不在 18 范围内。
  • 使用了当前账号不支持的尺寸。

相关页面