GPT Image 2 API-Dokumente
GPT Image 2 API-Dokumente
GPT Image 2 APIQuickstartAuthenticationPricing

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.

Environment
export BASE_URL="http://localhost:3000"
export API_KEY="YOUR_API_KEY"

2. Submit an image generation task

Submit (text-to-image)
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:

200 OK
{
  "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 (read outputImageUrls)
  • 2 = failed (read errorCode / errorMessage)

Polling every 2 seconds is recommended. The 30-second provider grace window means frequent polls are safe.

Poll once
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:

status: 0 (PENDING)
{
  "id": "tsk_01J9XA5M2R9W4QZC4PYJF3N7ND",
  "type": "image",
  "status": 0,
  "createdAt": "2026-04-22T09:00:00.000Z",
  "completedAt": null,
  "creditsUsed": 3,
  "creditRefunded": false
}

Completed snapshot example:

status: 1 (COMPLETED)
{
  "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.

Image-to-image
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.

GPT Image 2 API

Generate images and videos with Nano Banana, Sora 2, Veo 3.1, Kling, and more — through a single REST API.

Authentication

Authenticate every API request with a Bearer token and manage your API keys from the API Keys page.

Inhaltsverzeichnis

1. Prepare auth and base URL2. Submit an image generation task3. Poll until terminal state4. Optional: image-to-image in the same endpointNext steps