跳到主要内容

生成图像

本页示例中的 {BASE_URL} 表示 https://api.uniall.ai。

使用 gpt-image-2 生成图片。接口同步返回图片 URL。

接口参数与示例​

Endpoint​

POST /v1/images/generations/

请求体参数​

参数类型必填说明
modelstring是固定使用 gpt-image-2。
promptstring是图片生成提示词。
sizestring否输出尺寸,例如 1024x1024;也可使用 auto。
qualitystring否low、medium 或 high。
output_formatstring否png、jpeg 或 webp,默认 png。
backgroundstring否适用于 gpt-image-2。auto(模型根据提示词决定背景)、opaque(不透明背景)或 transparent(透明背景)。省略或传 null 时默认 auto。
ninteger否默认 1,范围为 1 到 8。
response_formatstring否使用 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"
}'

响应字段​

FieldTypeRequiredTitleDescription
createdintegerYes
dataarrayYes
usageobjectYes

响应示例​

成功示例​

{
"created": 1777105463,
"data": [
{
"url": "https://xxxxxx/xxx.jpg"
}
]
}