GPT Image: create image
POST/v1/images/generations
Generate images from a prompt with the GPT Image series; results return in the same request. For reference images use Edit image.
The image is generated within this HTTP request and can take a while; set a client timeout of 240 seconds or more. After a timeout, disconnect or 5xx the image may still be generated and billed. Synchronous requests have no idempotency protection, so resubmitting charges again. Use Create image task (POST /v1/images/tasks) when you need safe retries.
The current image route does not guarantee support for quality, background, output_format, output_compression, moderation, user or stream. Omit these fields.
Models and limits
| Model | Rule group | Endpoints | n | Reference images | prompt limit (chars) |
|---|---|---|---|---|---|
gpt-image-2 | GPT Image series | /v1/images/generations/v1/images/edits/v1/images/tasks | 1–4 | 1–16images on edits only | 32,000 |
gpt-image-2.5 | GPT Image series | /v1/images/generations/v1/images/edits/v1/images/tasks | 1–4 | 1–16images on edits only | 32,000 |
gpt-image-2.5-flare | GPT Image series | /v1/images/generations/v1/images/edits/v1/images/tasks | 1–4 | 1–16images on edits only | 32,000 |
gpt-image-2.5-sunburst | GPT Image series | /v1/images/generations/v1/images/edits/v1/images/tasks | 1–4 | 1–16images on edits only | 32,000 |
gpt-image-2.6 | GPT Image series | /v1/images/generations/v1/images/edits/v1/images/tasks | 1–4 | 1–16images on edits only | 32,000 |
gpt-image-2.6-flare | GPT Image series | /v1/images/generations/v1/images/edits/v1/images/tasks | 1–4 | 1–16images on edits only | 32,000 |
gpt-image-2.6-sunburst | GPT Image series | /v1/images/generations/v1/images/edits/v1/images/tasks | 1–4 | 1–16images on edits only | 32,000 |
Headers
AuthorizationstringRequiredBearer <API_KEY>.Content-TypestringRequiredapplication/json. Only JSON bodies are supported.
Request bodyJSON
modelstringRequiredA GPT Image model ID, case-sensitive. Available models are listed below.
- GPT Image series
gpt-image-2gpt-image-2.5gpt-image-2.5-flaregpt-image-2.5-sunburstgpt-image-2.6gpt-image-2.6-flaregpt-image-2.6-sunburst
promptstringRequiredDescribe the image to create.
Must not be empty; up to 32,000 characters.
nintegerOptionalDefault1Supports 1–4.
Billed as per-image price × count, reserved from
nat submission.sizestringOptionalOmit to let the model choose. Common dimensions are listed below. Other sizes are handled according to model capability; check the returned image for its actual dimensions.
Use a lowercase
xbetween width and height, not×.Supported values
1024x10241:11536x10243:21024x15362:3
response_formatstringOptionalOmit or send
url, then read the image from the returneddata.
Returns
HTTP 200 with the list of images.
GPT Image does not accept the image reference field here; use POST /v1/images/edits.
createdintegerOptionalCreation time in Unix seconds.
dataobject[]OptionalGenerated images, one per item.
Show child fields (4)
urlstringOptionalDownload URL. Use it as returned and save the image promptly; do not send your API key when downloading.
b64_jsonstringOptionalBase64 image data, which may be returned instead of
url. Decode it to save.revised_promptstringOptionalThe prompt the model used, when present.
width / height / sizeinteger / stringOptionalImage dimensions, as width and height or
WxH, when present.
output_formatstringOptionalFile format, when present.
usageobjectOptionalToken usage, for reference only. Usage logs show the actual charge.
Errors
Errors return {"error": {"message": "...", "type": "...", "code": "..."}}.
| HTTP | code | Cause and action |
|---|---|---|
| 400 | — | Invalid parameters such as missing model, n above 128 or × in size; see error.message. |
| 400 | asset_reference_not_found | The asset:// asset does not exist or is not yours. |
| 401 | — | The API key is invalid, expired or disabled. |
| 403 | insufficient_user_quota | Insufficient balance or key quota. |
| 403 | — | The key does not allow this model, or the IP is restricted. |
| 429 | — | Rate limited; retry later. |
| 503 | model_not_found | No channel is currently available for the model. |
| 524 | — | Gateway timeout while waiting (an HTML page). The image may still be generated and billed; check usage logs before retrying, or use asynchronous image tasks. |
curl -X POST https://ling-light.com/v1/images/generations \
-H "Authorization: Bearer $LINGLIGHT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.6",
"prompt": "A seated orange cat in soft morning light, watercolor illustration",
"n": 1,
"size": "1536x1024"
}'const response = await fetch('https://ling-light.com/v1/images/generations', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.LINGLIGHT_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"model": "gpt-image-2.6",
"prompt": "A seated orange cat in soft morning light, watercolor illustration",
"n": 1,
"size": "1536x1024"
}),
})
console.log(response.status, await response.json())import os
import requests
response = requests.post(
"https://ling-light.com/v1/images/generations",
headers={
"Authorization": f"Bearer {os.environ['LINGLIGHT_API_KEY']}",
},
json={
"model": "gpt-image-2.6",
"prompt": "A seated orange cat in soft morning light, watercolor illustration",
"n": 1,
"size": "1536x1024",
},
timeout=60,
)
print(response.status_code, response.json()){
"created": 1795660800,
"data": [
{
"url": "https://media.example.com/images/example.png",
"width": 1024,
"height": 1024,
"revised_prompt": "An orange cat on a windowsill in soft morning light, clean illustration"
}
],
"output_format": "png",
"usage": {
"input_tokens": 20,
"output_tokens": 1056,
"total_tokens": 1076
}
}