跳到主要内容

GPT-Image-2.5

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

GPT Image 2.5 提供两个公开模型 ID:

  • gpt-image-2.5-flare
  • gpt-image-2.5-sunburst

两个模型使用相同的 OpenAI 兼容同步图像契约。文生图使用 /v1/images/generations;请求包含参考图时,使用 /v1/images/edits。

当前 API Key 可用的模型,以 GET /v1/models 返回的模型列表为准。

适用场景​

GPT Image 2.5 适合:

  • 同步文生图;
  • 使用一张或多张参考图进行图片编辑;
  • 调整输出尺寸、质量和格式;
  • 获取 URL 或 Base64 图片响应。

接口​

GET /v1/models
POST /v1/images/generations
POST /v1/images/edits

图片接口会等待上游结果,并在同一个响应中返回生成图片,不会创建需要轮询的任务。

鉴权​

Authorization: Bearer sk-***
Content-Type: application/json

也可以使用以下兼容 Header:

x-api-key: sk-***

模型可用性​

curl "{BASE_URL}/v1/models" \
-H "Authorization: Bearer sk-***"

成功响应会列出当前 API Key 可见的模型 ID:

{
"object": "list",
"data": [
{
"id": "gpt-image-2.5-flare",
"object": "model",
"created": 0,
"owned_by": "uniall"
},
{
"id": "gpt-image-2.5-sunburst",
"object": "model",
"created": 0,
"owned_by": "uniall"
}
]
}

请求参数​

参数类型必填说明
modelstring是gpt-image-2.5-flare 或 gpt-image-2.5-sunburst。
promptstring是生成或编辑指令,最长 32,000 个字符。
sizestring否auto 或 WIDTHxHEIGHT,默认 auto。
qualitystring否auto、low、medium、high、xhigh 或 max,默认 auto。
ninteger否输出图片数量,默认 1,范围为 1 到 10。
output_formatstring否png、jpeg 或 webp,默认 png。
backgroundstring否auto(模型根据提示词决定背景)、opaque(不透明背景)或 transparent(透明背景)。省略或传 null 时默认 auto。
response_formatstring否url 或 b64_json,默认 b64_json。
imagesarray条件必填/v1/images/edits 的 JSON 参考图数组,每项使用 {"image_url":"..."}。
maskobject否/v1/images/edits 的 JSON 蒙版,使用 {"image_url":"..."},作用于第一张参考图。

背景设置​

背景参数待上线。background 放在请求体顶层。

  • auto:模型根据提示词决定背景;省略或传 null 时使用此默认值。
  • opaque:指定不透明背景。
  • transparent:指定透明背景;output_format 必须为 png 或 webp,未传时默认 png。

非法 background 值,或 transparent 与 jpeg 的组合,会在请求校验阶段返回 HTTP 400,不会开始生成。

适用于本页的同步生成和编辑接口。 结果格式仍由 response_format 选择 url 或 b64_json,默认 b64_json。

尺寸规则​

显式传入 WIDTHxHEIGHT 时:

  • 宽和高必须是正整数,且都是 16 的倍数;
  • 长边不能超过 3840 像素;
  • 宽高比不能超过 3:1;
  • 总像素必须在 655,360 到 8,294,400 之间。

如果希望根据请求和参考图上下文自动选择尺寸,使用 auto。

文生图示例​

curl -X POST "{BASE_URL}/v1/images/generations" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.5-flare",
"prompt": "An orange cat sticker, full subject visible, transparent background",
"size": "1024x1024",
"quality": "medium",
"background": "transparent",
"output_format": "png",
"n": 1,
"response_format": "url"
}'

JSON 图片编辑示例​

请求包含一张或多张参考图时,使用 /v1/images/edits。

curl -X POST "{BASE_URL}/v1/images/edits" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.5-sunburst",
"prompt": "Keep the product shape and remove the background to make it transparent",
"images": [
{"image_url": "https://example.com/product.png"}
],
"size": "auto",
"quality": "high",
"background": "transparent",
"output_format": "png",
"response_format": "url"
}'

每张 JSON 参考图使用 HTTP(S) 图片 URL,或 PNG、JPEG、WebP Base64 Data URL。单次请求最多可以传入 16 张参考图。

Base64 图片编辑示例​

使用 JSON 编辑请求时,将参考图作为完整的 Base64 Data URL 传入 images[].image_url。

curl -X POST "{BASE_URL}/v1/images/edits" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.5-sunburst",
"prompt": "Keep the product shape and remove the background to make it transparent",
"images": [
{
"image_url": "data:image/png;base64,BASE64_IMAGE_DATA"
}
],
"size": "1024x1024",
"quality": "high",
"background": "transparent",
"output_format": "png",
"response_format": "url"
}'

Data URL 必须包含 MIME 前缀,例如 data:image/png;base64,...、data:image/jpeg;base64,... 或 data:image/webp;base64,...。

multipart 图片编辑​

本地文件建议使用 multipart。多张参考图可以重复传入 image[]。

curl -X POST "{BASE_URL}/v1/images/edits" \
-H "Authorization: Bearer sk-***" \
-F "model=gpt-image-2.5-sunburst" \
-F "prompt=Keep the product shape and remove the background to make it transparent" \
-F "background=transparent" \
-F "output_format=png" \
-F "image[]=@product.png" \
-F "response_format=url"

multipart 蒙版可以使用 mask=@mask.png。蒙版必须是带 Alpha 通道的 PNG,小于 4 MB,并且与第一张参考图尺寸一致。

响应示例​

{
"created": 1789121337,
"size": "1024x1024",
"output_format": "png",
"data": [
{
"url": "https://api.uniall.ai/generated-media/example.png"
}
],
"usage": {
"prompt_tokens": 23,
"completion_tokens": 425,
"total_tokens": 448,
"prompt_tokens_details": {
"cached_tokens": 0,
"text_tokens": 23,
"image_tokens": 0
},
"completion_tokens_details": {
"text_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0
},
"usage_source": "upstream_response"
}
}

当 response_format 为 b64_json 时,每个 data 项返回 b64_json 而不是 url。该值是纯 Base64 内容,不包含 data:image/...;base64, 前缀。

Base64 响应示例​

如果应用需要在 JSON 响应中直接获取图片字节,将 response_format 设置为 b64_json。

curl -X POST "{BASE_URL}/v1/images/generations" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.5-flare",
"prompt": "An orange cat sticker, full subject visible, transparent background",
"size": "1024x1024",
"quality": "medium",
"background": "transparent",
"output_format": "png",
"response_format": "b64_json"
}'

响应中的 b64_json 是纯 Base64 内容,不包含 data:image/...;base64, 前缀:

{
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
}
]
}

相关页面​