OpenAI Image Generation
Official Documentation
Introduction
Given a text prompt and/or input image, the model will generate new images. OpenAI provides multiple powerful image generation models that can create, edit, and modify images based on natural language descriptions.
Supported Models
Currently supported models include:
| Model | Description |
|---|---|
| gpt-image-2 | GPT-Image-2 image generation and editing model, supporting multi-image editing capabilities, able to create new composite images based on multiple input images |
| gpt-image-2.5-sunburst | Most capable GPT-Image-2.5 model, optimized for precise image generation and editing. The dated snapshot gpt-image-2.5-sunburst-2026-09-08 is also supported. |
| gpt-image-2.5-flare | Fast GPT-Image-2.5 model for high-quality everyday image generation and editing. The dated snapshot gpt-image-2.5-flare-2026-09-08 is also supported. |
Request Examples
# Generate an image and return a temporary URL
curl https://www.unodetech.xyz/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
"model": "gpt-image-2",
"prompt": "A cute little sea otter",
"n": 1,
"size": "1024x1024",
"response_format": "url"
}'
# Maximum-quality GPT Image 2.5 generation
curl https://www.unodetech.xyz/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
"model": "gpt-image-2.5-sunburst",
"prompt": "A cute little sea otter",
"quality": "max",
"size": "1024x1024"
}'
# Transparent background with WebP output
curl https://www.unodetech.xyz/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
"model": "gpt-image-2",
"prompt": "A cute little sea otter",
"background": "transparent",
"output_format": "webp"
}'Response Example:
{
"created": 1589478378,
"data": [
{
"url": "https://cdn.example.com/generated-images/...?...",
"revised_prompt": "A cute little sea otter playing in the water, with round eyes and fluffy fur"
}
],
"background": "opaque",
"output_format": "png",
"quality": "high",
"size": "1024x1024",
"usage": {
"total_tokens": 100,
"input_tokens": 50,
"output_tokens": 50,
"input_tokens_details": {
"text_tokens": 10,
"image_tokens": 40
}
}
}# GPT Image 2.5 image editing
curl https://www.unodetech.xyz/v1/images/edits \
-H "Authorization: Bearer $API_KEY" \
-F image="@otter.png" \
-F mask="@mask.png" \
-F model="gpt-image-2.5-sunburst" \
-F prompt="A cute little sea otter wearing a beret" \
-F size="1024x1024" \
-F response_format="url"
# gpt-image-2 multi-image editing example
curl https://www.unodetech.xyz/v1/images/edits \
-H "Authorization: Bearer $API_KEY" \
-F "model=gpt-image-2" \
-F "image[]=@body-lotion.png" \
-F "image[]=@bath-bomb.png" \
-F "image[]=@incense-kit.png" \
-F "image[]=@soap.png" \
-F "prompt=Create an elegant gift basket containing these four items" \
-F "quality=high"Response Example:
{
"created": 1713833628,
"data": [
{
"url": "https://cdn.example.com/generated-images/...?..."
}
],
"usage": {
"total_tokens": 100,
"input_tokens": 50,
"output_tokens": 50,
"input_tokens_details": {
"text_tokens": 10,
"image_tokens": 40
}
}
}Request
Endpoints
Create Image
POST /v1/images/generationsCreate images based on text prompts.
Edit Image
POST /v1/images/editsCreate edited or extended images based on one or more original images and prompts.
JSON image-edit requests
Image editing supports both multipart/form-data uploads and application/json request bodies. For JSON requests, provide source images in the images array. Each image reference must contain either an image_url (a URL or Base64 data URL) or a file_id. A mask can use the same reference format. All other allowed edit parameters remain the same.
{
"model": "gpt-image-2.5-sunburst",
"prompt": "A cute little sea otter wearing a beret",
"images": [{ "image_url": "https://example.com/otter.png" }],
"mask": { "file_id": "file-mask" },
"quality": "max"
// ...other image-edit parameters
}Authentication Method
Include the following in the request header for API key authentication:
Authorization: Bearer $API_KEYWhere $API_KEY is your API key.
Request Body Parameters
Create Image (/v1/images/generations)
URL responses
For GPT Image models that only return Base64, the API stores the generated image and returns a temporary signed URL when URL delivery is available. This parameter is handled by the API compatibility layer and does not require native upstream support for response_format.
Before use, a platform administrator must enable image URL delivery in the current environment and include the current API key or traffic in its rollout. Otherwise, response_format=url returns 503. Clients do not configure or receive Bunny credentials.
Edit Image (/v1/images/edits)
Custom dimensions
For gpt-image-2, gpt-image-2.5-sunburst, and gpt-image-2.5-flare (including their dated snapshots), size can be a custom WIDTHxHEIGHT value such as 1536x864. Custom dimensions must meet all of these constraints:
- Width and height must be multiples of 16.
- The aspect ratio must be between 1:3 and 3:1.
- Neither edge can exceed 3840 pixels.
- The total pixel count must be between 655,360 and 8,294,400 pixels.
Resolutions above 2560x1440 are experimental.
Response
Successful Response
Both endpoints return a response containing a list of image objects.
usage Fields
Image Object
Each object in the data array contains:
Each image object contains either url or b64_json; clients must not assume that both fields are present. URL response example:
{
"url": "https://cdn.example.com/generated-images/...?...",
"revised_prompt": "A cute little sea otter playing in the water, with round eyes and fluffy fur"
}Response Format and URL Delivery
response_format | Behavior |
|---|---|
| Omitted | Preserves the model or upstream provider's default response format. GPT Image models usually return b64_json. |
b64_json | Requests Base64 image data in the response. |
url | Requests an image URL. Native URLs pass through; eligible Base64 results are stored and replaced with temporary signed URLs. |
Temporary URLs expire. Download or transfer the image soon after receiving the response instead of treating the URL as permanent. If a recoverable URL-delivery failure occurs, the API may return Base64 and set X-Image-Delivery-Fallback: base64. Clients requesting response_format=url should inspect both the response field and this header.
The returned URL includes its access signature and can be downloaded directly with HTTP GET; do not attach the API Authorization header. Keep the complete query string because it is part of the signature:
IMAGE_URL=$(jq -r '.data[0].url // empty' response.json)
test -n "$IMAGE_URL" && curl --fail --location "$IMAGE_URL" --output generated.pngURL delivery applies to non-streaming requests that return one complete JSON response. Do not combine response_format=url with stream=true; process streaming image requests using the selected model's streaming event format.
URL Delivery Errors
| HTTP status | Error code | Recommended action |
|---|---|---|
400 | Invalid request | Ensure response_format is the lowercase value url or b64_json. |
502 | image_url_delivery_failed | The image was generated, but storage or URL signing failed in strict mode. Retry later without aggressive immediate retries. |
502 | image_response_too_large | The generated response exceeded the server processing limit. Reduce the image count or dimensions. |
503 | image_url_delivery_unavailable | URL delivery is not enabled for the current model, API key, or environment. Use b64_json or wait for an administrator to enable it. |
503 | Other image_delivery_* errors | URL-delivery capacity or runtime state is temporarily unavailable. Retry with backoff. |
Best Practices
Prompt Writing Tips
- Use clear and specific descriptions
- Specify important visual details
- Describe expected artistic style and atmosphere
- Pay attention to composition and perspective instructions
Parameter Selection Tips
-
Size Selection
- 1024x1024: General scene best choice
- 1536x1024/1024x1536: Suitable for horizontal/vertical scenes
-
Quality
- quality=high: For images requiring fine details
- quality=xhigh or quality=max: GPT Image 2.5 only; use for higher-detail final assets when increased latency and cost are acceptable
- quality=auto: Let the model choose the optimal quality
Common Questions
-
Image generation failed
- Check if the prompt complies with content policies
- Confirm file format and size limits
- Verify API key permissions
-
Results do not match expectations
- Optimize prompt description
- Adjust quality and style parameters
- Consider using image editing or variation features
Last updated on
