Docs / Image Series / GPT Image / Sync
Native OpenAI image format (synchronous)
Synchronous OpenAI image endpoints: text-to-image uses POST /v1/images/generations (JSON); image-to-image and image editing use POST /v1/images/edits (multipart/form-data). Supports the quality parameter; the 2.6 series supports animated GIF output with configurable frame count and per-frame duration.
Real-time success rate (--:--:--)
The GPT Image 2 (gpt-image-2) image editing API is compatible with the OpenAI Images Edits format. It edits or extends the original image via multipart/form-data file uploads. This API is synchronous: the response carries the generated result directly, so no task polling is needed.
- Compared with image generation: image editing is a synchronous API that passes images as file uploads, while image generation is an async API that passes images as image URLs. - The generated image is returned directly as base64 (b64_json) or a temporary URL; save it promptly.Text-to-image / image-to-image endpoint selection#
| Scenario | Endpoint | Request format | Description |
|---|---|---|---|
| Text-to-image | POST /v1/images/generations | application/json | Submit a text prompt only and generate images directly |
| Image-to-image / image editing | POST /v1/images/edits | multipart/form-data | Upload one or more reference images, combined with a prompt for editing |
Use `/v1/images/generations` to generate images from text only; use `/v1/images/edits` when you need to upload reference images.
/v1/images/generations: synchronous image generation#
The synchronous text-to-image endpoint follows the OpenAI Images API format: submit JSON and the generated result is returned directly. Image editing still uses the /v1/images/edits multipart endpoint below.
POST /v1/images/generations
Request parameters#
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | gpt-image-2 | Model name; supports gpt-image-2, gpt-image-2.5-flare, gpt-image-2.5-sunburst, gpt-image-2.6-flare, gpt-image-2.6-sunburst, gpt-image-web |
prompt | string | Yes | — | Describes the image to generate |
n | integer | No | 1 | Number of images to generate; actual returned count follows data, billed by successfully generated images |
size | string | No | auto | Image size, e.g. 1024x1024, 1536x1024, 1024x1536, or auto; custom sizes are also supported (see the size constraints below) |
quality | string | No | auto | low, medium, high; xhigh and max are supported only by the 2.5 series (gpt-image-2.5-flare, gpt-image-2.5-sunburst) and the 2.6 series (gpt-image-2.6-flare, gpt-image-2.6-sunburst) |
output_format | string | No | png | Output image format: png, jpeg, webp, gif; gif is supported only by the 2.6 series models |
frame_count | integer | No | 9 | Total number of GIF frames, 2–16; only valid with output_format=gif, see Animated GIF output below |
frame_duration_ms | integer | No | 200 | Playback duration of each GIF frame in milliseconds, 20–2000, rounded to the nearest 10 ms; only valid with output_format=gif |
response_format | string | No | b64_json | Response format compatibility parameter: b64_json (default) or url; see the response_format section below |
output_format (image format, with GIF)#
output_format selects the output image format: png (default), jpeg, webp, and gif. gif is supported only by the two 2.6 models gpt-image-2.6-flare and gpt-image-2.6-sunburst, producing animated GIFs for stickers, looping animations, and similar use cases. See Animated GIF output below for details.
Animated GIF output#
When generating animated GIFs, both /v1/images/generations and /v1/images/edits accept the following fields:
| Field | Values | Default | Description |
|---|---|---|---|
frame_count | 2–16 frames | 9 | Total number of frames in the animation |
frame_duration_ms | 20–2000, rounded to the nearest 10 ms | 200 | Playback duration of each frame, in milliseconds |
size | auto or WIDTHxHEIGHT | auto | Per-frame canvas size (see below) |
`size` means the per-frame size, but total pixels accumulate over frames: for GIF output, size describes the width and height of each finished frame — the dimensions the animation plays back at — and all frames share the same canvas. However, the total pixel budget is calculated as frame count × per-frame pixels (× `n`), with the same cap as still images (8,294,400 pixels). For example, frame_count=9 + size=1024x1024 totals 9 × 1,048,576 ≈ 9.4MP, which exceeds the budget and returns a 400 error; with 9 frames the largest per-frame size is 960x960 (9 × 921,600 = 8,294,400 exactly). Prefer smaller frame sizes for GIF output, such as 512x512 (GIF frames are not subject to the 0.65MP minimum area that applies to still images). If the request exceeds the limits, reduce frame_count, shrink the frame dimensions, or lower n — or use size=auto to let the API choose a frame size within the model's limits.
In the prompt, describe the subject, the motion, and how the animation should loop (for example, "the motion loops and returns to the starting pose") to get a natural loop. The defaults (frame_count=9, frame_duration_ms=200) correspond to a loop of roughly 1.8 seconds.
GIF output limitations: streaming (stream), partial images (partial_images), and output_compression are not supported. frame_count and frame_duration_ms are only valid with output_format=gif; sending them with another output format returns a 400 error.
curl --request POST \
--url https://api.apimax.ai/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2.6-sunburst",
"prompt": "A cat waving hello, with the motion looping back to the starting pose",
"size": "512x512",
"output_format": "gif",
"frame_count": 9,
"frame_duration_ms": 200
}'Request example#
curl --request POST \
--url https://api.apimax.ai/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-image-2",
"prompt": "A minimalist white cat icon",
"size": "1024x1024",
"quality": "medium"
}'response_format (compatibility parameter)#
GPT Image natively returns base64 image data only. For compatibility with the DALL·E ecosystem, the platform additionally supports the response_format parameter on both /v1/images/generations and /v1/images/edits:
| Value | Behavior |
|---|---|
b64_json | Default. Returns the image data as base64 in data[].b64_json |
url | The platform uploads the generated image to hosted storage and returns data[].url; b64_json is no longer included |
- When omitted or empty, the parameter is treated as
b64_json; any other value (e.g.binary) returns a 400 error - The
urlpoints to a platform-hosted image address; download and save it promptly before the link expires
Authentication#
All endpoints require Bearer token authentication. Create your key on the API Key management page and add it to the request header:
Authorization: Bearer YOUR_API_KEY/v1/images/edits: image-to-image and editing#
POST /v1/images/edits
The request body is multipart/form-data (not JSON). Core fields: upload one or more source images as image, together with a prompt describing how to edit them.
| Mode | Description |
|---|---|
| Whole-image editing / style rewrite | Send only image + prompt; the model edits the image as a whole based on the original |
| Multi-image composition | Send multiple image[] files; the model blends multiple reference images |
Request parameters (form fields)#
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | — | Model name; supports gpt-image-2, gpt-image-2.5-flare, gpt-image-2.5-sunburst, gpt-image-2.6-flare, gpt-image-2.6-sunburst, gpt-image-web |
image | file | Yes | — | Source image file to edit. For multiple images, repeat the image[] field |
prompt | string | Yes | — | Describes the desired edit |
n | integer | No | 1 | Number of images to generate; actual returned count follows data, billed by successfully generated images |
size | string | No | auto | Output size, e.g. 1024x1024, 1536x1024, auto |
quality | string | No | auto | Render quality: low/medium/high/auto; xhigh and max are supported only by the 2.5 and 2.6 series models |
output_format | string | No | png | Output image format: png, jpeg, webp, gif; gif is supported only by the 2.6 series models |
frame_count | integer | No | 9 | Total number of GIF frames, 2–16; only valid with output_format=gif |
frame_duration_ms | integer | No | 200 | Playback duration of each GIF frame in milliseconds, 20–2000, rounded to the nearest 10 ms; only valid with output_format=gif |
response_format | string | No | b64_json | Response format compatibility parameter: b64_json (default) or url; behaves the same as on /v1/images/generations |
image (source image)#
- Supported formats:
.png,.jpg,.jpeg,.webp - Use the
imagefield for single-image editing; for multi-image composition, upload multiple files by repeating theimage[]field - Files are uploaded as multipart binary data, not as URLs
size#
| Value | Description |
|---|---|
auto | Decided by the model (default) |
1024x1024 | Square |
1536x1024 | Landscape |
1024x1536 | Portrait |
Common aspect ratios and high-resolution examples (all sizes below satisfy the official constraints and can be used directly):
| Ratio | Landscape | Portrait | Typical use cases |
|---|---|---|---|
| 1:1 | 1024x1024, 2048x2048 | same as landscape | Avatars, icons, e-commerce hero images |
| 4:3 / 3:4 | 1024x768, 2048x1536 | 768x1024, 1536x2048 | Article covers, illustrations |
| 3:2 / 2:3 | 1536x1024, 3072x2048 | 1024x1536, 2048x3072 | Photographic-style visuals, posters |
| 16:9 / 9:16 | 1280x720, 2048x1152, 3840x2160 | 720x1280, 1152x2048, 2160x3840 | Banners, desktop wallpapers, video covers, full-screen mobile assets |
| 21:9 / 9:21 | 2688x1152, 3360x1440 | 1152x2688, 1440x3360 | Ultrawide banners and wallpapers |
| 2:1 / 1:2 | 2048x1024 | 1024x2048 | Long-form graphics, infographics |
| 3:1 / 1:3 | 3072x1024 | 1024x3072, 1280x3840 | Extreme panoramic or tall images (aspect-ratio cap) |
3840x2160/2160x3840(4K) hits the total-pixel cap of 8,294,400 exactly and is the largest available 16:9 size- Higher resolutions consume more output tokens, take longer to generate, and cost more — choose only as large as you need
Beyond the sizes above, custom pixel sizes (WIDTHxHEIGHT, lowercase x) are also supported, subject to the official constraints:
- Width and height must both be multiples of 16
- Each side must be within 16–3840 pixels
- The aspect ratio must not exceed 1:3 (either orientation, e.g.
1024x3072is fine but1024x4096is not) - The total pixel count (width × height) must be within 655,360–8,294,400 (about 0.65MP–8.29MP; the cap is roughly 3840×2160)
Sizes violating these constraints are rejected with a 400 error.
Request examples#
Whole-image editing (single image):
curl --request POST \
--url https://api.apimax.ai/v1/images/edits \
--header 'Authorization: Bearer <token>' \
--form 'model=gpt-image-2' \
--form 'image=@/path/to/input.png' \
--form 'prompt=Change the background to a spring park with cherry blossoms in full bloom' \
--form 'size=1024x1024' \
--form 'quality=high'Multi-image composition:
curl --request POST \
--url https://api.apimax.ai/v1/images/edits \
--header 'Authorization: Bearer <token>' \
--form 'model=gpt-image-2' \
--form 'image[]=@/path/to/a.png' \
--form 'image[]=@/path/to/b.png' \
--form 'prompt=Blend these two images into a single movie poster'Python (requests):
import requests
url = "https://api.apimax.ai/v1/images/edits"
headers = {"Authorization": "Bearer <token>"}
files = {
"image": open("input.png", "rb"),
}
data = {
"model": "gpt-image-2",
"prompt": "Replace the sky with a starry night sky",
"size": "1024x1024",
}
resp = requests.post(url, headers=headers, files=files, data=data)
print(resp.json())Response example#
Returns the standard OpenAI Images format synchronously; data[].b64_json is the base64 encoding of the generated image:
{
"created": 1757156493,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
}
],
"usage": {
"input_tokens": 312,
"output_tokens": 4160,
"total_tokens": 4472,
"input_tokens_details": {
"text_tokens": 12,
"image_tokens": 300
}
}
}Decode b64_json to get the image binary. Image-to-image incurs additional image input token usage from reference images (see usage.input_tokens_details.image_tokens).
The generated result is determined by what data actually returns: individual images may fail to generate, in which case only the successful images are returned and billed (e.g. with n=4 and 2 images succeeded, 2 images are returned and billed).
If the request specifies response_format=url, each item returns a url field (a platform-hosted image link) and no longer contains b64_json:
{
"created": 1757156493,
"data": [
{
"url": "https://<storage-host>/img/image_xxxxxxxx.png"
}
]
}Error codes#
| Status code | Meaning |
|---|---|
| 400 | Invalid request parameters (missing image/prompt, unsupported format, etc.) |
| 401 | Authentication failed; check your API key |
| 403 | Insufficient account balance; top up and try again |
| 403 | The token does not have access to this model |
| 429 | Too many requests; try again later |
| 500 | Internal server error; try again later |

