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
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Use gpt-image-2. |
prompt | string | Yes | Image generation or editing prompt. |
image | string/object | Conditional | Reference image for editing. |
images | array | Conditional | Multiple reference images when supported. |
size | string | Yes | Output dimensions, such as 1024x1024. |
quality | string | No | low, medium, or high. Default: medium. |
output_format | string | No | png, jpeg, or webp. |
background | string | No | auto (model chooses from the prompt), opaque (opaque background), or transparent (transparent background). Omitted or null: auto. |
n | integer | No | Output image count. Default: 1; range: 1 to 8. |
response_format | string | No | Prefer 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 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.
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; usesizeinstead. - Passing
qualityoutsidelow,medium, orhigh. - Requesting
noutside1to8. - Using an unsupported size for the current account.