GPT Image 2.5
Image and video tasks share GET /v1/tasks/{id} to query status and GET /v1/tasks/{id}/content to download results. Image results use roles image_0–image_3; select the returned role when downloading.
Flare / Sunburst · generation and editing · up to 16 references · 1–4 outputs · 1K / 2K / 4K
Create a task with POST https://api.tokenlio.ai/v1/images/generations, poll its status, then download the images. Generation and editing use the same JSON endpoint.
Before you start
Copy the Flare or Sunburst API model ID from the model catalog and replace example/gpt-image-2.5-flare below. This placeholder is not a callable model ID. Consult the catalog for availability and prices.
1. Quick request
Provide your Tokenlio API Key through TOKENLIO_API_KEY. Creation, polling and content requests require Authorization: Bearer <TOKENLIO_API_KEY>.
BASE_URL='https://api.tokenlio.ai'
curl "$BASE_URL/v1/images/generations" \
-H "Authorization: Bearer $TOKENLIO_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"model":"example/gpt-image-2.5-flare","prompt":"A ginger cat by a window, afternoon light, watercolor illustration","size":"1:1","resolution":"1k","quality":"high","n":1,"output_format":"png"}'Example 202 response:
{
"id": "dfc68868-d388-4d83-a173-d44e47a8bec7",
"model": "example/gpt-image-2.5-flare",
"status": "queued",
"assets": []
}Save id. 202 means accepted, not finished. This endpoint does not return images or data[].b64_json immediately. Do not parse it as an OpenAI synchronous image response; follow the task workflow below.
2. Request parameters
| Parameter | Type | Required / default | Description |
|---|---|---|---|
model | string | Required | Exact API model ID from the catalog, not its display name |
prompt | string | Required | Non-empty prompt; also required with references or a mask |
size | string | auto | Automatic, aspect ratio or exact pixels; see rules below |
resolution | string | 1k | 1k / 2k / 4k, lowercase |
quality | string | auto | low / medium / high / xhigh / max / auto |
n | integer | 1 | Number of output images, 1–4 |
output_format | string | png | png / jpeg / webp; not jpg |
output_compression | integer | Optional | 0–100; JPEG / WebP only; omit for PNG |
background | string | Optional | auto / opaque / transparent; transparency requires PNG or WebP |
moderation | string | low | low / auto |
image_urls | string[] | Optional | Up to 16 reference image URLs; base64 entries are not supported |
mask_url | string | Optional | One PNG mask URL or Data URI; requires image_urls |
Size and resolution
- Automatic:
"size": "auto". - Ratios:
1:1,3:2,2:3,4:3,3:4,5:4,4:5,16:9,9:16,2:1,1:2,21:9,9:21,3:1,1:3. Ratio andresolutiondetermine output dimensions together. - Exact pixels: for example,
"size": "1600x1200", with lowercasex. Both sides must be multiples of 16 and at most 3840 pixels. The longer-to-shorter side ratio cannot exceed 3:1; total pixels must be 655,360–8,294,400. - Exact-pixel
sizedetermines dimensions instead ofresolution; omitresolutionin this mode.
Reference generation
{
"model": "example/gpt-image-2.5-flare",
"prompt": "Keep the product in the first image and use the colors of the second image to create a clean product poster",
"image_urls": [
"https://YOUR_PUBLIC_CDN/product.png",
"https://YOUR_PUBLIC_CDN/style.jpg"
],
"size": "3:2",
"resolution": "2k",
"n": 2,
"output_format": "png"
}POST this JSON to the same /v1/images/generations endpoint. Explain each reference image's purpose in the prompt; do not reuse video-specific input fields.
Masked editing
{
"model": "example/gpt-image-2.5-flare",
"prompt": "Replace the masked area with white tulips while keeping the original lighting and composition",
"image_urls": ["https://YOUR_PUBLIC_CDN/original.png"],
"mask_url": "https://YOUR_PUBLIC_CDN/mask.png",
"size": "auto",
"output_format": "png"
}- Use a PNG with an Alpha channel, at most 4 MiB. Its dimensions must exactly match the original
image_urls[0], not the requested output size. - Fully transparent areas (Alpha=0) mark the area to edit. Other areas guide preservation, but pixel-perfect preservation is not guaranteed.
- Only one mask is supported; it applies to the first reference image.
- Alternatively, use
data:image/png;base64,<complete PNG Base64>formask_url. Supply real encoded PNG data, not a placeholder. - Editing uses this JSON generation endpoint, not multipart or
/v1/images/edits.
Input limits
Provide public HTTPS/443 direct URLs without login, custom headers or redirects for references and remote masks. Local/private addresses, Cookie-protected pages and HTML pages are unsuitable. Keep URLs valid and content unchanged during processing.
PNG / JPEG / WebP references are recommended, with each side at most 6000 pixels. Download or format errors may surface during task processing; 202 does not mean all inputs have passed validation.
The JSON body limit is 8 MiB, including Data URIs. Send only documented fields; unknown fields, duplicate fields and null are rejected. Send integers as numbers, not strings. Do not send stream, response_format, seed, negative_prompt or video-only task parameters.
3. Poll the task
Use the same API Key that created the task:
TASK_ID='dfc68868-d388-4d83-a173-d44e47a8bec7'
curl "$BASE_URL/v1/tasks/$TASK_ID" \
-H "Authorization: Bearer $TOKENLIO_API_KEY"Poll every 5–15 seconds, backing off after transient errors. Query the original task instead of creating another one.
status | Meaning and action |
|---|---|
queued | Waiting; keep polling |
processing | Still processing; keep polling |
succeeded | Finished; read images from assets |
failed | Failed; inspect error.code and error.message |
id and model identify the original task. assets is empty until results are available. An optional message provides guidance; if it says not to resubmit, keep querying the same id or contact support with that ID.
Example success response with two images:
{
"id": "dfc68868-d388-4d83-a173-d44e47a8bec7",
"model": "example/gpt-image-2.5-flare",
"status": "succeeded",
"assets": [
{ "role": "image_0", "url": "https://SIGNED_DOWNLOAD_URL/image-0.png" },
{ "role": "image_1", "url": "https://SIGNED_DOWNLOAD_URL/image-1.png" }
]
}assets[].role starts at image_0, up to image_3. Process the returned array one image at a time. assets[].url expires; query the task again to obtain fresh links.
4. Download images
Use assets[].url directly, without adding your API Key. Alternatively, use the authenticated content endpoint with an explicit returned role:
curl --location "$BASE_URL/v1/tasks/$TASK_ID/content?role=image_0" \
-H "Authorization: Bearer $TOKENLIO_API_KEY" \
-o image-0.pngThe content endpoint returns a 307 redirect, not URL JSON. Change role for other images and choose .png, .jpeg or .webp to match output_format.
Protect credentials and image links
Do not use --location-trusted. Custom clients must remove Authorization when following cross-host redirects. Do not publish or log API Keys or signed links; anyone holding a valid link can download the image. Save images promptly rather than treating temporary URLs as permanent addresses.
Retries, pricing and errors
- Disable automatic POST retries. Without
Idempotency-Key, each POST creates a separate task, even with identical parameters, and may incur another charge. If creation times out without an ID, check console usage records first. - Optionally send one
Idempotency-Keyheader: 1–128 non-whitespace printable ASCII characters. The same API Key, identifier and parameters return the original task; reusing the identifier with different parameters returns 409. Use a new identifier for a new task. - Check the catalog for prices and console usage records for the actual charge after processing. Image count, quality, dimensions and inputs affect usage. Image requests do not accept
max_charge_amount. - 400: check fields, integer types, dimensions, transparency/format compatibility and mask requirements; do not retry unchanged.
- 401 / 403: check Key validity and permission to use the model.
- 402: insufficient balance; add funds before creating new tasks.
- 404: check the task ID and use the Key that created it.
- 409: check for a conflicting idempotency identifier or a download attempted before results are ready.
- 429: reduce request frequency/concurrent tasks and check usage limits.
- 5xx: retry queries with backoff; for creation, first establish whether the task was accepted to avoid duplicates.
For HTTP errors, inspect error.type / error.message. For a task with status=failed, inspect error.code / error.message. Keep the task ID for troubleshooting; HTTP 200 alone does not mean image generation succeeded.
