GPT-Image-2 API — Text-to-Image & Image Editing Guide
How to use the GPT-Image-2 API for text-to-image and image-to-image generation via APIMaster.ai. Sync or async modes. Access gpt-image-2 at discounted pricing with your API key.
GPT-Image-2 image generation
- Model:
gpt-image-2 - Endpoints: sync
POST https://apimaster.ai/v1/images/generations· asyncPOST https://apimaster.ai/v1/images/generations/async - Features: Text-to-image; image-to-image with up to 16 reference images (URL + base64 mix)
Do not call this model via
/v1/chat/completions. You will get HTTP 400 with a pointer to the Images API.
Call modes
| Mode | Endpoint | When to use |
|---|---|---|
| Sync (recommended) | POST https://apimaster.ai/v1/images/generations |
OpenAI SDK compatibility — one request returns { "data": [{ "url" }] } (platform polls server-side) |
| Async submit | POST https://apimaster.ai/v1/images/generations/async |
Long jobs, batch pipelines — returns task_id immediately; you poll for the result |
Both modes use the same JSON body (model, prompt, size, resolution, etc.).
Quick start (sync)
curl -s "https://apimaster.ai/v1/images/generations" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-image-2","prompt":"An orange cat at sunset, watercolor"}'
Success response
{
"created": 1717500000,
"data": [{ "url": "https://apimaster.ai/imgs/....png" }]
}
Client timeout hints (sync)
| Tier | Suggested read timeout |
|---|---|
| 1k default | ≥ 180s |
| 2k / medium | ≥ 300s |
| 4k / high | ≥ 600s |
Auth
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Body parameters
| Field | Type | Required | Notes |
|---|---|---|---|
model |
string | yes | gpt-image-2 |
prompt |
string | yes | Scene description; safety moderation applies |
n |
integer | no | 1 only (numeric, no quotes) |
size |
string | no | Aspect ratio, default 1:1 |
resolution |
string | no | 1k / 2k / 4k, default 1k |
image_urls |
array | no | Reference images → image-to-image |
official_fallback |
boolean | no | Allow upgrade to official-capable channel on standard-request retry, default false |
size values
auto, 1:1, 3:2, 2:3, 4:3, 3:4, 5:4, 4:5, 16:9, 9:16, 2:1, 1:2, 3:1, 1:3, 21:9, 9:21, or pixel strings like 3840x2160.
resolution (sample pixels)
| size | 1k | 2k | 4k |
|---|---|---|---|
1:1 |
1024×1024 | 2048×2048 | 2880×2880 |
16:9 |
1536×864 | 2048×1152 | 3840×2160 |
All 15 ratios support 4K.
image_urls
- Max 16 images
- Public URLs and base64 data URIs can be mixed
- Omit
sizeto follow input resolution; setsizeto force output aspect ratio
Examples
16:9 @ 2K (sync)
curl -s "https://apimaster.ai/v1/images/generations" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "a corgi astronaut on the moon, cinematic",
"size": "16:9",
"resolution": "2k"
}'
Errors (sync)
| HTTP | Meaning |
|---|---|
| 400 | Bad parameters, or wrong endpoint (chat) |
| 401 | Bad API key |
| 402 | Insufficient balance |
| 408 | Generation timeout — lower resolution/quality or switch to async |
| 429 | Rate limited |
Async mode: submit
POST https://apimaster.ai/v1/images/generations/async with the same body. Returns immediately:
{
"code": 200,
"data": [{ "status": "submitted", "task_id": "task_01KPQ7J7DWB7QZ3WCEK3YVPBRA" }]
}
Async mode: poll result
curl -s "https://apimaster.ai/v1/tasks/TASK_ID?model=gpt-image-2" \
-H "Authorization: Bearer YOUR_API_KEY"
?model=gpt-image-2selects the correct channel- Image URL when done:
data.result.images[0].url[0] - Submit response (
/images/generations/async) usesstatus: submitted. Poll response (GET /tasks/...) often returnspendingwhile generating;processing/in_progressare also possible. Terminal states:completedorfailed.
| Phase | Typical status |
Meaning |
|---|---|---|
| Submit OK | submitted |
Only in async submit data[] |
| Queued / running | pending, processing, in_progress |
Keep polling — pending is normal, not an error |
| Success | completed |
Read data.result.images[0].url[0] |
| Failure | failed, error, cancelled |
Inspect error fields in the response |
- Poll after 10–20s, every 3–5s
Notes
- Use Images API endpoints, not Chat Completions.
- Prefer
sizefor aspect ratio; avoid repeating ratio inprompt. - Billing by resolution tier; see console for your account.