GPT Image 2

OpenAI GPT Image 2 image generation. Publicly, use a single model id: gpt-image-2. It supports both prompt-only generation and reference-image editing.

Model

Model NameOutputMode
gpt-image-2Image URLsText-to-image, image-to-image

Pricing

Priced per output resolution tier:

ResolutionCreditsPrice
1k (default)4.7 credits$0.0235
2k9.4 credits$0.047
4k14.1 credits$0.0705

Create Task

curl -X POST https://api.aivideoapi.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "callback_url": "https://your-server.com/webhook",
    "input": {
      "prompt": "Turn this product photo into a clean studio shot on a white background",
      "image_urls": [
        "https://example.com/source.png"
      ],
      "aspect_ratio": "1:1",
      "nsfw_checker": true
    }
  }'

Request Body

FieldTypeRequiredDescription
modelstringYesMust be gpt-image-2
inputobjectYesGeneration parameters, see below
callback_urlstringNoOptional callback URL for completion/failure notifications

Input Parameters

FieldTypeRequiredDescription
promptstringConditionallyPrompt text, max 20,000 characters
image_urlsstring[]ConditionallyReference image URLs for editing. Maximum 16 images.
aspect_ratiostringNoOutput image aspect ratio, defaults to auto. One of: 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; you may also pass an explicit pixel size (e.g. 1881x836, 887x1774). auto is treated as 1:1. See Size & Resolution for the exact pixels of each tier.
resolutionstringNoOutput resolution tier, defaults to 1k. One of: 1k, 2k, 4k. Combined with aspect_ratio it determines the actual pixels — see Size & Resolution.
nsfw_checkerbooleanNoSafety check toggle, defaults to true

At least one of prompt or image_urls must be provided.

Size & Resolution

aspect_ratio sets the ratio (or an explicit pixel size) and resolution sets the tier (1k / 2k / 4k). Their combination maps to the following actual pixels. 4k supports all 15 ratios; aspect_ratio=auto is treated as 1:1.

Ratio1k2k4k
1:11024×1024 / 1254×12542048×20482880×2880
3:21536×10242048×13603520×2336
2:31024×15361360×20482336×3520
4:31024×7682048×15363312×2480
3:4768×10241536×20482480×3312
5:41280×1024 / 1448×10862560×20483216×2576
4:51024×1280 / 1122×14022048×25602576×3216
16:91536×864 / 1672×9412048×11523840×2160
9:16864×1536 / 941×16721152×20482160×3840
2:12048×1024 / 1774×8872688×13443840×1920
1:21024×2048 / 887×17741344×26881920×3840
3:11881×836 / 1536×5123072×10243840×1280
1:3887×1774 / 512×15361024×30721280×3840
21:92016×864 / 1915×8212688×11523840×1648
9:21864×2016 / 821×19151152×26881648×3840

You can also pass any pixel size from the table above directly via aspect_ratio (e.g. 1881x836 / 887x1774).

Example: Text-to-Image

curl -X POST https://api.aivideoapi.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "callback_url": "https://your-server.com/webhook",
    "input": {
      "prompt": "A cinematic night city poster with neon reflections on a rainy street.",
      "aspect_ratio": "16:9",
      "nsfw_checker": true
    }
  }'

Example: Image-to-Image

curl -X POST https://api.aivideoapi.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "callback_url": "https://your-server.com/webhook",
    "input": {
      "prompt": "Convert this room into a warm Scandinavian interior design render",
      "image_urls": [
        "https://example.com/room.jpg"
      ],
      "aspect_ratio": "3:2"
    }
  }'

Example: 4K Output

curl -X POST https://api.aivideoapi.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "callback_url": "https://your-server.com/webhook",
    "input": {
      "prompt": "An ancient castle under a starry sky, cinematic composition",
      "aspect_ratio": "16:9",
      "resolution": "4k"
    }
  }'

Response

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "397ce9f2-c04e-4244-ac33-3af19a7cc297"
  }
}

Query Task

curl https://api.aivideoapi.ai/v1/tasks/{taskId} \
  -H "Authorization: Bearer sk-your-api-key"

Status flow: pending -> processing -> completed or failed.

Completed

{
  "id": "397ce9f2-c04e-4244-ac33-3af19a7cc297",
  "status": "completed",
  "model": "gpt-image-2",
  "created_at": 1775383908,
  "completed_at": 1775383910,
  "output": {
    "urls": [
      "https://file.aivideoapi.ai/images/2026/04/05/abc123.png"
    ],
    "metadata": {
      "model": "gpt-image-2-image-to-image",
      "costTime": 70
    }
  }
}

Failed

{
  "id": "57c8772c-f834-46f3-9b7d-81f92e104050",
  "status": "failed",
  "model": "gpt-image-2",
  "created_at": 1775383908,
  "error": {
    "code": "upstream_error",
    "message": "Generation failed"
  }
}

Failed tasks are automatically refunded.

Callback Notifications

Pass callback_url when creating the task. When the task completes or fails, we send a POST request whose payload matches the GET /v1/tasks/{taskId} response.


Error Codes

When a request fails, the API returns a JSON error response:

{
  "error": {
    "code": "insufficient_credits",
    "message": "Your credit balance is too low. Please top up.",
    "type": "billing_error"
  }
}

Error Reference

HTTP StatusCodeTypeDescription
400invalid_requestinvalid_request_errorMissing or invalid parameters
401invalid_api_keyauthentication_errorAPI key is invalid, disabled, or deleted
402insufficient_creditsbilling_errorCredit balance too low, please top up
403ip_not_allowedpermission_errorRequest IP not in the key's allowlist
404model_not_foundinvalid_request_errorModel does not exist or is inactive
404task_not_foundinvalid_request_errorTask ID does not exist
429rate_limit_exceededrate_limit_errorToo many requests, please slow down
429spend_limit_exceededbilling_errorKey spend limit reached (hourly/daily/total)
500internal_errorapi_errorUnexpected server error
503upstream_errorupstream_errorUpstream AI provider returned an error

Common Scenarios

invalid_request (400)

Returned when required fields are missing or invalid.

{
  "error": {
    "code": "invalid_request",
    "message": "'model' is required.",
    "type": "invalid_request_error"
  }
}

insufficient_credits (402)

Your balance is too low. Check your balance with GET /v1/credits and top up in Dashboard > Billing.

invalid_api_key (401)

Possible causes:

  • The key does not start with sk-
  • The key has been disabled or deleted
  • The user account has been banned

upstream_error (503)

The upstream AI provider returned an error. This may happen when:

  • The input contains sensitive or prohibited content
  • The provider is temporarily unavailable
  • The request parameters are not supported by the provider

Credits are automatically refunded when a task fails due to upstream errors.