AI Video APIAI Video API


Nano Banana 2

Google Gemini 3.1 Flash Image generation model. Combines lightning-fast speed with Pro-level quality. Supports text-to-image, image editing, 4K output, accurate text rendering, and strong character consistency.

Model

Model NameOutputAspect Ratios
nano-banana-2Image (JPG/PNG)1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9, 1:4, 4:1, 1:8, 8:1, auto

Pricing

Per-resolution billing:

ResolutionCreditsPrice
1K (default)16 credits$0.08
2K24 credits$0.12
4K36 credits$0.18

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": "nano-banana-2",
    "input": {
      "prompt": "A cute cat wearing sunglasses sitting on a beach, digital art style",
      "resolution": "1K",
      "aspect_ratio": "16:9",
      "output_format": "png"
    }
  }'

Request Body

FieldTypeRequiredDescription
modelstringYesMust be nano-banana-2
inputobjectYesGeneration parameters, see below
callback_urlstringNoURL to receive task completion/failure notifications

Input Object

FieldTypeRequiredDescription
promptstringYesText description of desired image (max 20,000 characters)
resolutionstringNo1K (default), 2K, or 4K
aspect_ratiostringNoAspect ratio, default auto. See Aspect Ratios
output_formatstringNojpg (default) or png
image_urlsstring[]NoUp to 14 image URLs for image editing (JPEG, PNG, WebP)

Aspect Ratios

StandardWide/TallUltra-wide
1:12:3, 3:221:9
4:3, 3:49:16, 16:94:1, 1:4
4:5, 5:4auto8:1, 1:8

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": "nano-banana-2",
    "input": {
      "prompt": "A futuristic cityscape at sunset, neon lights reflecting on wet streets, cyberpunk style",
      "resolution": "2K",
      "aspect_ratio": "21:9",
      "output_format": "png"
    }
  }'

Example: Image Editing

curl -X POST https://api.aivideoapi.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana-2",
    "input": {
      "prompt": "Transform this photo into a watercolor painting style",
      "image_urls": [
        "https://example.com/photo.jpg"
      ],
      "resolution": "4K"
    }
  }'

Example: Text Rendering

curl -X POST https://api.aivideoapi.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana-2",
    "input": {
      "prompt": "A birthday card with the text 'Happy Birthday Sarah!' in elegant cursive font, floral border",
      "resolution": "2K",
      "aspect_ratio": "3:2",
      "output_format": "png"
    }
  }'

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 transitions: pending -> processing -> completed or failed.

Completed

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

Image URLs are permanent.

Failed

{
  "id": "57c8772c-f834-46f3-9b7d-81f92e104050",
  "status": "failed",
  "model": "nano-banana-2",
  "created_at": 1775383908,
  "error": {
    "code": "upstream_error",
    "message": "Image generation failed"
  }
}

When a task fails, pre-charged credits are automatically refunded.

Callback

Pass callback_url when creating the task. The system will automatically send a POST request to your URL when the task completes or fails. The format matches the query task 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.