生成图像
本页示例中的 {BASE_URL} 表示 https://api.uniall.ai。
使用 gpt-image-2 生成图片。接口同步返回图片 URL。
接口参数与示例
Endpoint
POST /v1/images/generations/
请求体参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 固定使用 gpt-image-2。 |
prompt | string | 是 | 图片生成提示词。 |
size | string | 否 | 输出尺寸,例如 1024x1024;也可使用 auto。 |
quality | string | 否 | low、medium 或 high。 |
output_format | string | 否 | png、jpeg 或 webp,默认 png。 |
background | string | 否 | 适用于 gpt-image-2。auto(模型根据提示词决定背景)、opaque(不透明背景)或 transparent(透明背景)。省略或传 null 时默认 auto。 |
n | integer | 否 | 默认 1,范围为 1 到 8。 |
response_format | string | 否 | 使用 url 获取图片 URL。 |
背景设置
背景参数待上线。background 放在请求体顶层。
auto:模型根据提示词决定背景;省略或传null时使用此默认值。opaque:指定不透明背景。transparent:指定透明背景;output_format必须为png或webp,未传时默认png。
非法 background 值,或 transparent 与 jpeg 的组合,会在请求校验阶段返回 HTTP 400,不会开始生成。
请求示例
示例
{
"model": "gpt-image-2",
"prompt": "A cute baby sea otter",
"size": "1024x1536",
"quality": "medium",
"output_format": "png"
}
curl -X POST "{BASE_URL}/v1/images/generations/" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A cute baby sea otter",
"size": "1024x1536",
"quality": "medium",
"output_format": "png"
}'
透明背景
以下透明背景请求使用 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": "1024x1024",
"quality": "medium",
"background": "transparent",
"output_format": "png",
"n": 1,
"response_format": "url"
}'
响应字段
| Field | Type | Required | Title | Description |
|---|---|---|---|---|
created | integer | Yes | ||
data | array | Yes | ||
usage | object | Yes |
响应示例
成功示例
{
"created": 1777105463,
"data": [
{
"url": "https://xxxxxx/xxx.jpg"
}
]
}