> ## Documentation Index
> Fetch the complete documentation index at: https://apixo.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Nano Banana 2

> Google image generation API for text-to-image and image-to-image workflows

## Overview

Nano Banana 2 is a high-quality image generation model for text-to-image creation and reference-guided image generation. Use this page when you are ready to call the API after trying the model in the APIXO playground.

| Capability       | Value                                                                                                       |
| ---------------- | ----------------------------------------------------------------------------------------------------------- |
| Model ID         | `nano-banana-2`                                                                                             |
| Modes            | `text-to-image`, `image-to-image`                                                                           |
| Prompt length    | 1-20000 characters                                                                                          |
| Reference images | Required for `image-to-image`; up to 14 URLs                                                                |
| Aspect ratios    | `auto`, `1:1`, `1:4`, `4:1`, `1:8`, `3:2`, `2:3`, `3:4`, `4:3`, `4:5`, `5:4`, `8:1`, `9:16`, `16:9`, `21:9` |
| Resolution tiers | `1k`, `2k`, `4k`                                                                                            |
| Output formats   | `png`, `jpeg`, `jpg`                                                                                        |

## Endpoint and authentication

Base URL:

```text theme={null}
https://api.apixo.ai/api/v1
```

| Method | Endpoint                                    | Purpose                               |
| ------ | ------------------------------------------- | ------------------------------------- |
| `POST` | `/generateTask/nano-banana-2`               | Submit a generation task              |
| `GET`  | `/statusTask/nano-banana-2?taskId={taskId}` | Poll task status and retrieve results |

All requests require your APIXO API key:

```http theme={null}
Authorization: Bearer YOUR_API_KEY
```

Submit requests also require:

```http theme={null}
Content-Type: application/json
```

## Copy-paste async quickstart

This minimal request submits a text-to-image task and returns a `taskId`.

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/nano-banana-2" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-image",
      "prompt": "a cozy cyberpunk cafe with neon lights and rain-soaked streets",
      "aspect_ratio": "3:2",
      "resolution": "2k"
    }
  }'
```

Successful response:

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}
```

Save the `taskId`; you need it to poll for the final result.

## Poll for result

```bash theme={null}
curl -X GET "https://api.apixo.ai/api/v1/statusTask/nano-banana-2?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

Processing response:

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "processing",
    "createTime": 1767965610929
  }
}
```

Success response:

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/xxx.png\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965652317,
    "costTime": 41388
  }
}
```

Failed response:

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "SensitiveContent",
    "failMsg": "Content violates safety policy, please adjust the prompt",
    "createTime": 1767965610929,
    "completeTime": 1767965620132
  }
}
```

Parse `resultJson` after `state` becomes `success`:

```javascript theme={null}
const payload = JSON.parse(data.resultJson);
const imageUrls = payload.resultUrls;
```

## Request body

### Text-to-image

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "text-to-image",
    "prompt": "a fox in watercolor style",
    "aspect_ratio": "16:9",
    "resolution": "2k",
    "output_format": "png",
    "google_search": false
  }
}
```

### Image-to-image

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-image",
    "prompt": "make this scene look like sunrise with warm golden light",
    "image_urls": [
      "https://example.com/source.png"
    ],
    "aspect_ratio": "4:5",
    "resolution": "4k",
    "output_format": "jpeg",
    "google_search": false
  }
}
```

## Parameters

<ParamField body="request_type" type="string" required default="async">
  Result delivery mode. Use `async` for polling with `statusTask`, or `callback` for webhook delivery.
</ParamField>

<ParamField body="callback_url" type="string">
  Required when `request_type` is `callback`. Must be a public HTTPS URL that can receive the final task payload. See [Webhooks](/docs/api-reference/webhooks).
</ParamField>

<ParamField body="input" type="object" required>
  Nano Banana 2 input parameters.

  <Expandable title="properties">
    <ParamField body="mode" type="string" required>
      Generation mode. Supported values: `text-to-image`, `image-to-image`.
    </ParamField>

    <ParamField body="prompt" type="string" required>
      Text prompt describing the desired image or edit. Leading and trailing whitespace is ignored for validation. Supports 1-20000 characters.
    </ParamField>

    <ParamField body="image_urls" type="string[]">
      Reference image URLs. Required for `image-to-image`; provide 1-14 public, directly fetchable image URLs.
    </ParamField>

    <ParamField body="aspect_ratio" type="string" required>
      Output aspect ratio. Supported values: `auto`, `1:1`, `1:4`, `4:1`, `1:8`, `3:2`, `2:3`, `3:4`, `4:3`, `4:5`, `5:4`, `8:1`, `9:16`, `16:9`, `21:9`.
    </ParamField>

    <ParamField body="resolution" type="string" required>
      Output resolution tier. Supported values: `1k`, `2k`, `4k`. The API accepts either lowercase or uppercase values and normalizes them for the selected route.
    </ParamField>

    <ParamField body="output_format" type="string" default="png">
      Output image format. Supported values: `png`, `jpeg`, `jpg`. Use `jpeg` for the JPEG format; `jpg` is accepted as an alias.
    </ParamField>

    <ParamField body="google_search" type="boolean" default="false">
      Enables web search context when supported by the active route. Defaults to `false`.
    </ParamField>
  </Expandable>
</ParamField>

<Note>
  `aspect_ratio` and `resolution` are required. `auto` is accepted for `aspect_ratio`; on some routes it lets the upstream service choose the default framing.
</Note>

## Response format

### Submit task response

`POST /generateTask/nano-banana-2` returns a task ID when the task is accepted:

<ResponseField name="code" type="integer">
  API status code. `200` means the task was accepted.
</ResponseField>

<ResponseField name="message" type="string">
  Human-readable status message.
</ResponseField>

<ResponseField name="data.taskId" type="string">
  Unique task identifier used with the status endpoint.
</ResponseField>

### Status response fields

<ResponseField name="taskId" type="string">
  Unique task identifier.
</ResponseField>

<ResponseField name="state" type="string">
  Current task state: `processing`, `success`, or `failed`.
</ResponseField>

<ResponseField name="resultJson" type="string">
  JSON string containing the generated image URLs. Present when `state` is `success`.
</ResponseField>

<ResponseField name="failCode" type="string">
  Machine-readable failure code. Present when `state` is `failed`.
</ResponseField>

<ResponseField name="failMsg" type="string">
  Human-readable failure message. Present when `state` is `failed`.
</ResponseField>

<ResponseField name="createTime" type="integer">
  Task creation timestamp in Unix milliseconds.
</ResponseField>

<ResponseField name="completeTime" type="integer">
  Task completion timestamp in Unix milliseconds. Present after completion.
</ResponseField>

<ResponseField name="costTime" type="integer">
  Processing duration in milliseconds. Present after successful completion when available.
</ResponseField>

## Webhook callback mode

Use callback mode when your backend should receive the final result automatically instead of polling.

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/nano-banana-2" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "callback",
    "callback_url": "https://your-server.com/webhooks/apixo",
    "input": {
      "mode": "image-to-image",
      "prompt": "turn this product photo into a polished studio ad",
      "image_urls": [
        "https://example.com/product.png"
      ],
      "aspect_ratio": "1:1",
      "resolution": "2k",
      "output_format": "png"
    }
  }'
```

See [Webhooks](/docs/api-reference/webhooks) for delivery requirements and retry behavior.

## Billing

Nano Banana 2 is billed per generated image. The selected `resolution` determines the unit price.

| Resolution | APIXO price     |
| ---------- | --------------- |
| `1k`       | `$0.05 / image` |
| `2k`       | `$0.08 / image` |
| `4k`       | `$0.12 / image` |

For current route and market comparison pricing, see [Pricing](https://apixo.ai/pricing).

## Latency and polling

Actual latency may vary by prompt complexity, reference image accessibility, selected resolution, route health, and current queue load. The backend returns `costTime` in milliseconds after completion when timing data is available.

| Stage               | Guidance                                                         |
| ------------------- | ---------------------------------------------------------------- |
| First poll          | Wait 10s-20s after task creation before the first status request |
| Poll interval       | Poll every 10s while `state` is `processing`                     |
| Production delivery | Use callback mode for high-concurrency workloads                 |

<Tip>
  Result URLs are available for 15 days by default. Download and store important outputs promptly.
</Tip>

Rate limits and concurrency can vary by account, API key, and route. If you receive `429`, slow down requests and retry with backoff. For account-level details, see [System APIs](/docs/api-reference/system).

## Errors and troubleshooting

### HTTP errors

| Code  | Meaning                                                   | What to do                                       |
| ----- | --------------------------------------------------------- | ------------------------------------------------ |
| `400` | Invalid request body, mode, parameter, or image URL shape | Fix the request before retrying                  |
| `401` | Missing or invalid API key                                | Check the `Authorization` header                 |
| `402` | Insufficient balance or quota                             | Add balance or switch account/key                |
| `403` | Key or route cannot access the model                      | Check permissions and route strategy             |
| `429` | Rate limit or concurrency limit reached                   | Retry with exponential backoff                   |
| `500` | Server or unmapped upstream error                         | Retry with backoff                               |
| `502` | Upstream service error                                    | Retry with backoff                               |
| `504` | Upstream timeout                                          | Retry or use callback mode for long-running jobs |

### Task failure codes

| Fail code              | Meaning                                          | What to do                                                             |
| ---------------------- | ------------------------------------------------ | ---------------------------------------------------------------------- |
| `PromptInvalid`        | Prompt was invalid or rejected upstream          | Revise the prompt                                                      |
| `SensitiveContent`     | Prompt or output violated safety policy          | Change the prompt or reference image                                   |
| `ImageFormatIncorrect` | A reference image could not be accepted upstream | Use a public, direct image URL in a common image format                |
| `MissingParameter`     | A required upstream parameter was missing        | Check `mode`, `prompt`, `aspect_ratio`, `resolution`, and `image_urls` |
| `RateLimited`          | Upstream rate limit was reached                  | Retry with backoff                                                     |
| `Timeout`              | Upstream timeout                                 | Retry, reduce input complexity, or use callback mode                   |
| `Unknown error`        | Upstream failure did not match a known rule      | Retry with backoff or contact support with the `taskId`                |

See [Error Codes](/docs/api-reference/errors) for the full error reference.

## Related links

* [Generation API Overview](/docs/models)
* [Generate Task](/docs/api-reference/generate-task)
* [Status Task](/docs/api-reference/status-task)
* [Webhooks](/docs/api-reference/webhooks)
* [Error Codes](/docs/api-reference/errors)
* [Parameter Specification](/docs/api-reference/parameters)
* [Routing Strategies](/docs/concepts/routing-strategies)
* [Nano Banana](/docs/models/image/nano-banana)
* [Nano Banana Pro](/docs/models/image/nano-banana-pro)
* [Pricing](https://apixo.ai/pricing)
