AI Video APIAI Video API


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)2.4 credits$0.012
2k4.8 credits$0.024
4k7.2 credits$0.036

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",
    "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, 5:4, 4:3, 3:2, 16:9, 21:9, 9:16, 4:5, 3:4, 2:3, 2:1, 1:2, 9:21. Constraint: when resolution=4k, must be explicitly set (not auto) and limited to 16:9, 9:16, 2:1, 1:2, 21:9, 9:21
resolutionstringNoOutput resolution tier, defaults to 1k. One of: 1k, 2k, 4k
nsfw_checkerbooleanNoSafety check toggle, defaults to true

At least one of prompt or image_urls must be provided.

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",
    "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",
    "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",
    "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.