GPT-Image-2
本页示例中的 {BASE_URL} 表示 https://api.uniall.ai。
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 | 是 | 输出尺寸,例如 1024x1024。 |
quality | string | 否 | low、medium 或 high。默认 medium。 |
output_format | string | 否 | png、jpeg 或 webp。 |
background | string | 否 | auto(模型根据提示词决定背景)、opaque(不透明背景)或 transparent(透明背景)。省略或传 null 时默认 auto。 |
n | integer | 否 | 输出图片数量,默认 1,范围为 1 到 8。 |
response_format | string | 否 | 生成资产建议使用 url。 |
背景设置
背景参数待上线。background 放在请求体顶层。
auto:模型根据提示词决定背景;省略或传null时使用此默认值。opaque:指定不透明背景。transparent:指定透明背景;output_format必须为png或webp,未传时默认png。
非法 background 值,或 transparent 与 jpeg 的组合,会在请求校验阶段返回 HTTP 400,不会开始生成。
适用于本页的同步生成和编辑接口。 既有 GPT Image 2 异步图片任务和图片聊天兼容请求也使用同一顶层参数。图片结果仍返回 URL。
文生图示例
curl -X POST "{BASE_URL}/v1/images/generations" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "An orange cat sticker, full subject visible, transparent background",
"size": "1024x768",
"quality": "low",
"background": "transparent",
"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 and remove the background to make it transparent",
"image": "https://example.com/input.png",
"size": "1024x1024",
"quality": "medium",
"background": "transparent",
"output_format": "png",
"n": 1,
"response_format": "url"
}'
响应示例
{
"created": 1778688000,
"data": [
{
"url": "https://example.com/generated.png"
}
]
}
常见错误
- 缺少
size。 - 传入
aspect_ratio;该模型应使用size。 quality不在low、medium、high范围内。n不在1到8范围内。- 使用了当前账号不支持的尺寸。