Quickstart
Submit a GPT Image task, poll until completion, and read outputImageUrls in minutes with curl.
This walkthrough focuses on image generation + polling only:
- Submit image task:
POST /api/ai/image/generate - Poll task state:
GET /api/ai/tasks/{id}
Examples use http://localhost:3000. In production, switch to https://gptimage2api.org.
1. Prepare auth and base URL
Authentication
Replace YOUR_API_KEY with a key created from the API Keys page. See Authentication for the full Bearer token flow.
export BASE_URL="http://localhost:3000"
export API_KEY="YOUR_API_KEY"2. Submit an image generation task
curl -sS -X POST "$BASE_URL/api/ai/image/generate" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A premium skincare bottle on warm ivory paper, embossed serif label, soft editorial side light",
"model": "gpt-image-2",
"aspectRatio": "4:5"
}'Typical response:
{
"taskId": "tsk_01J9XA5M2R9W4QZC4PYJF3N7ND",
"status": 0,
"creditsUsed": 3
}Keep taskId; polling uses it in the next step.
3. Poll until terminal state
Status values:
0= pending (keep polling)1= completed (readoutputImageUrls)2= failed (readerrorCode/errorMessage)
Polling every 2 seconds is recommended. The 30-second provider grace window means frequent polls are safe.
curl -sS "$BASE_URL/api/ai/tasks/$TASK_ID" \
-H "Authorization: Bearer $API_KEY"Repeat this same request every 2 seconds until status becomes 1 or 2.
Pending snapshot example:
{
"id": "tsk_01J9XA5M2R9W4QZC4PYJF3N7ND",
"type": "image",
"status": 0,
"createdAt": "2026-04-22T09:00:00.000Z",
"completedAt": null,
"creditsUsed": 3,
"creditRefunded": false
}Completed snapshot example:
{
"id": "tsk_01J9XA5M2R9W4QZC4PYJF3N7ND",
"type": "image",
"status": 1,
"outputImageUrls": [
"https://static.bananananoai.ai/u/42/2026-04-22/abc123.jpg"
],
"completedAt": "2026-04-22T09:00:32.000Z",
"creditsUsed": 3,
"creditRefunded": false
}4. Optional: image-to-image in the same endpoint
Set inputImageUrls to enter image-to-image mode. gpt-image-2 accepts up to 4 reference images.
curl -sS -X POST "$BASE_URL/api/ai/image/generate" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Keep the bottle shape, replace the background with matte ivory paper and add a soft studio shadow",
"model": "gpt-image-2",
"inputImageUrls": [
"https://static.bananananoai.ai/samples/product-01.jpg"
],
"aspectRatio": "4:5"
}'Next steps
- Read Generate image for request field details.
- Read Get task status for full response schema.
- Read Polling strategy for production backoff/timeout strategy.
- Review Pricing and credits & models to budget jobs.