GPT-Image-2
GPT-Image-2 Image Generation
- Asynchronous processing mode, returns task ID for subsequent queries
- OpenAI Images compatible protocol, supports text-to-image / image-to-image
- 15 image aspect ratios supported via the
sizefield - Output pixel tier controlled via
resolution(1k/2k/4k) - Up to 16 reference images, URL and base64 can be mixed
- Billed by resolution tier (1K / 2K / 4K)
POST
Documentation Index
Fetch the complete documentation index at: https://docs.apimart.ai/llms.txt
Use this file to discover all available pages before exploring further.
Authorizations
All endpoints require Bearer Token authenticationGet your API Key:Visit the API Key management page to get your API KeyInclude it in the request header:
Body
Image generation model nameFixed to
gpt-image-2Text description for image generation
- Supports English and Chinese, detailed descriptions recommended
- Pre-submission content moderation / safety review — violations are rejected immediately
Number of images to generateRange:
1Image aspect ratioSupported ratios, plus
Pixel dimensions can also be passed directly, such as
auto to let the server pick a suitable ratio automatically:| size | Type |
|---|---|
auto | Automatic |
1:1 | Square |
3:2 | Landscape |
2:3 | Portrait |
4:3 | Landscape |
3:4 | Portrait |
5:4 | Landscape |
4:5 | Portrait |
16:9 | Landscape |
9:16 | Portrait |
2:1 | Landscape |
1:2 | Portrait |
3:1 | Landscape |
1:3 | Portrait |
21:9 | Landscape |
9:21 | Portrait |
1881x836 / 887x1774.Output resolution tierOptions:
1k / 2k / 4ksize × resolution → actual pixel mapping:| size | 1k | 2k | 4k |
|---|---|---|---|
1:1 | 1024×1024 / 1254×1254 | 2048×2048 | 2880×2880 |
3:2 | 1536×1024 | 2048×1360 | 3520×2336 |
2:3 | 1024×1536 | 1360×2048 | 2336×3520 |
4:3 | 1024×768 | 2048×1536 | 3312×2480 |
3:4 | 768×1024 | 1536×2048 | 2480×3312 |
5:4 | 1280×1024 / 1448×1086 | 2560×2048 | 3216×2576 |
4:5 | 1024×1280 / 1122×1402 | 2048×2560 | 2576×3216 |
16:9 | 1536×864 / 1672×941 | 2048×1152 | 3840×2160 |
9:16 | 864×1536 / 941×1672 | 1152×2048 | 2160×3840 |
2:1 | 2048×1024 / 1774×887 | 2688×1344 | 3840×1920 |
1:2 | 1024×2048 / 887×1774 | 1344×2688 | 1920×3840 |
3:1 | 1881×836 / 1536×512 | 3072×1024 | 3840×1280 |
1:3 | 887×1774 / 512×1536 | 1024×3072 | 1280×3840 |
21:9 | 2016×864 / 1915×821 | 2688×1152 | 3840×1648 |
9:21 | 864×2016 / 821×1915 | 1152×2688 | 1648×3840 |
Reference image array (OpenAI standard field). Switches to image-to-image mode when provided.
Other OpenAI standard fields (
response_format, quality, style) are not supported and will be ignored. Task results only return url — please download and convert to base64 yourself if needed.Whether to fall back to the official channel
false: Do not use (default)true: Use the official channel
Usage Examples
Text-to-image (minimal request)Response
Response status code
Response data array
Querying Task Results
After successful submission, atask_id is returned. Poll the task status via GET /v1/tasks/{task_id}, see Task Query API for details.
Success Response Example
data.result.images[0].url[0]
Task Status
| Status | Meaning |
|---|---|
submitted | Submitted |
processing | Being processed upstream |
completed | Success, result.images available |
failed | Failed, check error.message |
Polling Recommendations
- Initial query delay: Wait 10~20 seconds after submission before first query
- Query interval: 3~5 seconds recommended, avoid millisecond-level polling
- Timeout reference: A single image typically completes in 30
60 seconds (observed53s)actual_time44 - Batch query: To query multiple tasks at once, use
POST /v1/tasks/batchwith body{"task_ids": ["task_xxx", "task_yyy"]}
Notes
- Asynchronous processing: Submission returns
task_id, poll/v1/tasks/{task_id}to get the final image URL - Content moderation:
promptis reviewed first — violations are rejected with no billing - Result URL: The platform mirrors upstream temporary signed links to its own R2 object storage, returning a stable link that clients can access directly
- URL validity:
expires_at = completed + 24hin the response is a hint field, please download or mirror to your own CDN promptly - Ratio conflict: Use the
sizefield for aspect ratio — avoid repeating it inpromptto prevent upstream ambiguity - Billing: Billed by resolution tier (1K / 2K / 4K), no charge on failure or moderation rejection
- 4K supported ratios: All 15 ratios above support 4K; you can also pass the corresponding pixel dimensions directly via
size - Task retention:
task_idis retained in the database for several days by default (configured byTASK_RETENTION_DAYS) — expired queries return “task does not exist or has expired”