Skip to main content

Generate Images

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

Use gpt-image-2 to generate images. The endpoint returns image URLs synchronously.

API Parameters and Examples​

Endpoint​

POST /v1/images/generations/

Request Body Parameters​

ParameterTypeRequiredDescription
modelstringYesUse gpt-image-2.
promptstringYesImage generation prompt.
sizestringNoOutput dimensions, such as 1024x1024, or auto.
qualitystringNolow, medium, or high.
output_formatstringNopng, jpeg, or webp. Default: png.
backgroundstringNoFor gpt-image-2. auto (model chooses from the prompt), opaque (opaque background), or transparent (transparent background). Omitted or null: auto.
nintegerNoDefault: 1; range: 1 to 8.
response_formatstringNoUse url for image URL results.

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.

Request Examples​

Example​

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

Transparent Background​

The transparent-background request below uses gpt-image-2 and returns an image 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"
}'

Response Fields​

FieldTypeRequiredTitleDescription
createdintegerYes
dataarrayYes
usageobjectYes

Response Examples​

Success Example​

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