Skip to main content

GPT-Image-2

In this page's examples, {BASE_URL} is https://api.uniall.ai.

Use gpt-image-2 for text-to-image and image editing through the OpenAI-compatible image endpoints. This model uses size to control both dimensions and aspect ratio. It does not support aspect_ratio.

Endpoint​

POST /v1/images/generations
POST /v1/images/edits

Use /v1/images/generations for text-to-image. Use /v1/images/edits when a reference image is included.

Authentication​

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

Request Parameters​

ParameterTypeRequiredDescription
modelstringYesUse gpt-image-2.
promptstringYesImage generation or editing prompt.
imagestring/objectConditionalReference image for editing.
imagesarrayConditionalMultiple reference images when supported.
sizestringYesOutput dimensions, such as 1024x1024.
qualitystringNolow, medium, or high. Default: medium.
output_formatstringNopng, jpeg, or webp.
backgroundstringNoauto (model chooses from the prompt), opaque (opaque background), or transparent (transparent background). Omitted or null: auto.
nintegerNoOutput image count. Default: 1; range: 1 to 8.
response_formatstringNoPrefer url.

Background Control​

Background control is pending release. Pass background at the top level of the request body.

  • auto: the model chooses the background from the prompt. This is the default when omitted or set to null.
  • opaque: request an opaque background.
  • transparent: request a transparent background. Set output_format to png or webp; if omitted, it defaults to png.

An invalid background value or a transparent/jpeg combination returns HTTP 400 during request validation, before generation starts.

Applies to both synchronous generation and editing endpoints on this page. Existing GPT Image 2 async image tasks and image-chat compatibility requests use the same top-level field. Image results remain URL-based.

Text-To-Image Example​

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"
}'

Image Editing Example​

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"
}'

Response Example​

{
"created": 1778688000,
"data": [
{
"url": "https://example.com/generated.png"
}
]
}

Common Errors​

  • Missing size.
  • Passing aspect_ratio; use size instead.
  • Passing quality outside low, medium, or high.
  • Requesting n outside 1 to 8.
  • Using an unsupported size for the current account.