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
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Use gpt-image-2. |
prompt | string | Yes | Image generation prompt. |
size | string | No | Output dimensions, such as 1024x1024, or auto. |
quality | string | No | low, medium, or high. |
output_format | string | No | png, jpeg, or webp. Default: png. |
background | string | No | For gpt-image-2. auto (model chooses from the prompt), opaque (opaque background), or transparent (transparent background). Omitted or null: auto. |
n | integer | No | Default: 1; range: 1 to 8. |
response_format | string | No | Use 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 tonull.opaque: request an opaque background.transparent: request a transparent background. Setoutput_formattopngorwebp; if omitted, it defaults topng.
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
| Field | Type | Required | Title | Description |
|---|---|---|---|---|
created | integer | Yes | ||
data | array | Yes | ||
usage | object | Yes |
Response Examples
Success Example
{
"created": 1777105463,
"data": [
{
"url": "https://xxxxxx/xxx.jpg"
}
]
}