# Nano Banana Image Generation

Create text-to-image and reference-guided image generation tasks with `nano-banana-2` or `nano-banana-pro`. Image generation runs asynchronously: submit a task, poll its status, and retrieve the generated image from `images[].url` once it succeeds.

## Endpoints & Authentication

```http
POST https://vip.brioi.com/v1/images/async/generations
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
```

Poll task status:

```http
GET https://vip.brioi.com/v1/images/async/generations/{task_id}
Authorization: Bearer YOUR_API_KEY
```

## Supported Models

| Model | Use Cases |
|---|---|
| `nano-banana-2` | General-purpose text-to-image, reference-guided generation, and fast image output. |
| `nano-banana-pro` | High-resolution images, product photography, complex instructions, and scenes requiring crisp text or fine detail. |

Model availability depends on your API key—query `GET /v1/models` for the authoritative list.

- `gemini-3.0-pro-image` and `gemini-3.1-flash-image` also work with this async endpoint, sharing the exact request fields and limits of `nano-banana-pro` and `nano-banana-2`, respectively. Alternatively, use [Gemini Native Sync Image Generation](https://docs.brioi.com/english/2552255m0.md).
- For **`nano-banana-2.1`**, use [Gemini Native Sync Image Generation](https://docs.brioi.com/english/2552255m0.md) (`POST /v1beta/models/nano-banana-2.1:generateContent`).

None of the image models above support `/v1/chat/completions`. Selecting them in a chat client will fail.

## Capabilities

| Model | Input | Capability | Asset Requirements |
|---|---|---|---|
| `nano-banana-2` | Omit `image_urls` | Text-to-image | Prompt only. |
| `nano-banana-2` | Provide `image_urls` | Reference-guided generation | 1–5 public direct image URLs, applied in array order. |
| `nano-banana-pro` | Omit `image_urls` | Text-to-image | Prompt only. |
| `nano-banana-pro` | Provide `image_urls` | Reference-guided generation | 1–14 public direct image URLs, applied in array order. |

## Request Parameters

| Parameter | Type | Required | Default | Description |
|---|---|---:|---|---|
| `model` | string | Yes | — | `nano-banana-2` or `nano-banana-pro` (also accepts `gemini-3.1-flash-image` or `gemini-3.0-pro-image`). |
| `prompt` | string | Yes | — | Image generation or editing instructions. Specify subject, scene, composition, material, lighting, and color for best results. |
| `image_urls` | string[] | No | — | Direct HTTPS URLs to reference images. Up to 5 images for `nano-banana-2`; up to 14 images for `nano-banana-pro`. Omit this field when not using reference images. |
| `aspect_ratio` | string | No | `9:16` | `nano-banana-2` supports `1:1`, `16:9`, `9:16`, `4:3`, `3:4`, `auto`. `nano-banana-pro` supports `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `4:5`, `5:4`, `9:16`, `16:9`, `21:9`, `auto`. Both models output `9:16` portrait when omitted or set to `auto`. Expresses a composition preference and does not guarantee strict adherence to the selected ratio. |
| `image_size` | string | No | `1K` | `1K`, `2K`, or `4K` (uppercase `K` required). Defaults to `1K` for both output resolution and billing when omitted. |
| `n` | integer | No | `1` | Only `1` is currently supported; omitting this field is recommended. |

New integrations only need the top-level fields listed above. Do not pass chat completion parameters such as `messages`, `temperature`, `top_p`, or `stream`.

## Text-to-Image Example

```bash
curl -X POST "https://vip.brioi.com/v1/images/async/generations" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana-2",
    "prompt": "An iced coffee on a wooden table in morning sunlight, lifestyle photography",
    "aspect_ratio": "1:1",
    "image_size": "1K"
  }'
```

## Reference Image Generation Example

```bash
curl -X POST "https://vip.brioi.com/v1/images/async/generations" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana-pro",
    "prompt": "Preserve the product structure and material, generate a studio hero shot on a pure white background with soft shadows, no text in the image",
    "image_urls": [
      "https://example.com/product-front.png",
      "https://example.com/product-side.png"
    ],
    "aspect_ratio": "1:1",
    "image_size": "4K"
  }'
```

## Creation Response

A successful submission returns a task ID:

```json
{
  "images": [],
  "progress": "10%",
  "status": "SUBMITTED",
  "task_id": "task_xxxxxxxxxxxxxxxxxxxxxxxx"
}
```

Save `task_id`. A successful creation response only indicates that the task has entered processing, not that the image has been generated.

## Polling Task Status

```bash
curl "https://vip.brioi.com/v1/images/async/generations/task_xxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

Poll every 3–5 seconds.

| Status | Action |
|---|---|
| `SUBMITTED` | Task submitted; continue polling. |
| `IN_PROGRESS` | Generating image; continue polling. |
| `SUCCESS` | Completed; read `images[].url`. |
| `FAILURE` | Failed; read `fail_reason`. |

Stop polling once the task reaches `SUCCESS` or `FAILURE`. `progress` may not appear in every response—clients must not rely on it to detect terminal states.

## Retrieving Results

Example response when generation succeeds:

```json
{
  "task_id": "task_xxxxxxxxxxxxxxxxxxxxxxxx",
  "status": "SUCCESS",
  "progress": "100%",
  "images": [
    {
      "index": 0,
      "url": "https://example.com/result.png",
      "mime_type": "image/png"
    }
  ]
}
```

| Field | Description |
|---|---|
| `images[].index` | Zero-based image index. |
| `images[].url` | Image download URL. |
| `images[].mime_type` | Image MIME type; some storage backends may return `application/octet-stream`. |
| `fail_reason` | Failure reason, present only when `status` is `FAILURE`. Raw diagnostic error text—do not parse against a fixed format. |

Poll responses may also include auxiliary fields such as `usage`; clients should not depend on them.

Download the image:

```bash
curl -L "https://example.com/result.png" -o result.png
```

Result URLs may expire—download or persist generated images promptly after the task succeeds.

## Limits & Error Handling

- `image_urls` accepts up to 5 images for `nano-banana-2` and up to 14 images for `nano-banana-pro`. Omit `image_urls` when not using reference images—do not pass an empty array.
- Reference image URLs must be publicly accessible direct HTTPS image links, not web pages, preview pages, or URLs requiring authentication.
- `image_size` only accepts `1K`, `2K`, or `4K`. Lowercase `k` and other size values are not part of the public API contract.
- `aspect_ratio` only accepts the values listed in the parameter table; unsupported ratios return a parameter error. Omitting `aspect_ratio` or passing `auto` generates a `9:16` portrait image.
- `aspect_ratio` expresses a composition preference and does not guarantee strict adherence to the selected ratio. If your workflow requires an exact aspect ratio, validate and crop the image after generation.
- Each task generates 1 image; `n` must be `1`.
- HTTP status codes: `400` invalid request parameters, `401` missing or invalid API key, `403` insufficient balance/quota or missing model permission, `404` task not found, `429` rate limit exceeded, `503` service temporarily unavailable, `500` / `502` transient server error.

