# Nano Banana 2.1

> Generate and edit 1K, 2K and 4K images with Google's Nano Banana 2.1. Combine up to 10 reference images for product visuals, posters and consistent creative assets. From 4 credits ($0.02) per image.

## Overview

- Submit: `https://api.poyo.ai/api/generate/submit`
- Status: `https://api.poyo.ai/api/generate/status/{task_id}`
- Page: https://poyo.ai/models/nano-banana-2-1
- Model page ID: `nano-banana-2-1`
- API model ID: `nano-banana-2.1`
- Category: Image
- Auth: `Authorization: Bearer $POYO_API_KEY`
- Create a key at https://poyo.ai/dashboard/api-key

This model uses PoYo's unified async API. POST the JSON body below, then poll status with the returned `task_id` or receive a webhook on `callback_url`. Failed tasks are not charged.

## Pricing

- 1K: 4 credits ($0.020) per image
- 2K: 6 credits ($0.030) per image
- 4K: 10 credits ($0.050) per image

For more details, see https://poyo.ai/models/nano-banana-2-1.

## API Information

The request envelope is always `{ model, input, callback_url? }`. Input fields below are nested under `input`.

### Request envelope

- `model` (`ModelEnum`, required):
  Nano Banana 2.1 model identifier
  - Options: `"nano-banana-2.1"`
- `callback_url` (`string`, optional):
  Webhook callback URL for result notifications
  - Examples: "https://your-domain.com/callback"

### Input Schema

Image generation or editing parameters.

The API accepts the following `input` parameters:

- `prompt` (`string`, required):
  Describe the image to create or how to edit reference images.
  - Length: 1 to 20000 characters
  - Examples: "An orange cat sitting by a window"
- `image_urls` (`list`, optional):
  Optional reference image URLs for image editing. When provided, pass an array of 1 to 10 HTTP(S) URLs.
  - Array of string
  - Length: 1 to 10
  - Examples: `["https://example.com/reference.png"]`
- `size` (`SizeEnum`, optional):
  Output aspect ratio. Defaults to auto when image_urls are provided, otherwise 1:1. auto is only supported for image editing and lets the model choose a ratio from the reference images.
  - Options: `"auto"`, `"1:1"`, `"2:3"`, `"3:2"`, `"3:4"`, `"4:3"`, `"4:5"`, `"5:4"`, `"9:16"`, `"16:9"`, `"21:9"`
  - Examples: "16:9"
- `resolution` (`ResolutionEnum`, optional):
  Output resolution.
  - Default: `"1K"`
  - Options: `"1K"`, `"2K"`, `"4K"`
  - Examples: "2K"

Required Parameters Example:

```json
{
  "model": "nano-banana-2.1",
  "input": {
    "prompt": "A warm sunlit studio portrait of an orange cat",
    "size": "1:1",
    "resolution": "1K"
  }
}
```

Full Example:

```json
{
  "model": "nano-banana-2.1",
  "input": {
    "prompt": "A warm sunlit studio portrait of an orange cat",
    "size": "1:1",
    "resolution": "1K",
    "image_urls": [
      "https://example.com/reference.png"
    ]
  }
}
```

Reference-image editing:

```json
{
  "model": "nano-banana-2.1",
  "input": {
    "prompt": "Keep the subject and replace the background with a watercolor garden",
    "image_urls": [
      "https://example.com/reference.png"
    ],
    "size": "auto",
    "resolution": "2K"
  }
}
```

### Output Schema

Submit returns a `task_id`. Poll `GET /api/generate/status/{task_id}` until `status` is `finished` or `failed`. Completed media is in `data.files`.

Response fields:

- `code` (`CodeEnum`, required):
  Business status code. `200` means success; any other value means the request failed. Always check this field: some validation errors return HTTP 200 with `code: 400` in the body.
  
  - `200`: Success
  - `400`: Invalid request parameters
  - `401`: Missing or invalid API key
  - `402`: Insufficient credits
  - `403`: Permission denied
  - `404`: Resource not found
  - `408`: Request timeout
  - `429`: Rate limit exceeded
  - `500`: Internal server error
  - `502`: Upstream service error
  - `503`: Service unavailable
  
  See [Error Codes](/api-manual/error-codes) for details.
  - Options: `200`, `400`, `401`, `402`, `403`, `404`, `408`, `429`, `500`, `502`, `503`
  - Examples: `200`
- `data` (`object`, required):

Example Response:

```json
{
  "code": 200,
  "data": {
    "task_id": "task_example",
    "status": "finished",
    "files": [
      {
        "file_url": "https://storage.poyo.ai/nano-banana-2-1/examples/museum-v1-bed486dbeaf1.jpg",
        "file_type": "image"
      }
    ]
  }
}
```

## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://api.poyo.ai/api/generate/submit \
  --header "Authorization: Bearer $POYO_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{"model":"nano-banana-2.1","input":{"prompt":"A warm sunlit studio portrait of an orange cat","size":"1:1","resolution":"1K"}}'
```

### Python

```python
import json
import os
import time
import requests

API = "https://api.poyo.ai"
headers = {
    "Authorization": f"Bearer {os.environ['POYO_API_KEY']}",
    "Content-Type": "application/json",
}
payload = json.loads("{\n  \"model\": \"nano-banana-2.1\",\n  \"input\": {\n    \"prompt\": \"A warm sunlit studio portrait of an orange cat\",\n    \"size\": \"1:1\",\n    \"resolution\": \"1K\"\n  }\n}")

submit = requests.post(f"{API}/api/generate/submit", headers=headers, json=payload)
submit.raise_for_status()
task_id = submit.json()["data"]["task_id"]

while True:
    status = requests.get(f"{API}/api/generate/status/{task_id}", headers=headers)
    status.raise_for_status()
    data = status.json()["data"]
    if data["status"] in ("finished", "failed"):
        print(data)
        break
    time.sleep(2)
```

### JavaScript

```javascript
const headers = {
  Authorization: `Bearer ${process.env.POYO_API_KEY}`,
  "Content-Type": "application/json",
};

const submit = await fetch("https://api.poyo.ai/api/generate/submit", {
  method: "POST",
  headers,
  body: JSON.stringify({
  "model": "nano-banana-2.1",
  "input": {
    "prompt": "A warm sunlit studio portrait of an orange cat",
    "size": "1:1",
    "resolution": "1K"
  }
}),
});

const submitted = await submit.json();
const taskId = submitted.data.task_id;

while (true) {
  const statusResponse = await fetch(`https://api.poyo.ai/api/generate/status/${taskId}`, { headers });
  const status = await statusResponse.json();
  if (["finished", "failed"].includes(status.data.status)) {
    console.log(status.data);
    break;
  }
  await new Promise((resolve) => setTimeout(resolve, 2000));
}
```

## Additional Resources

### Documentation

- [Model Playground](https://poyo.ai/models/nano-banana-2-1)
- [API Documentation](https://docs.poyo.ai/api-manual/image-series/nano-banana-2-1)
- [API Documentation (Markdown)](https://docs.poyo.ai/api-manual/image-series/nano-banana-2-1.md)
- [Task status](https://docs.poyo.ai/api-manual/task-management/query-task-status)
- [Webhooks](https://docs.poyo.ai/api-manual/task-management/webhooks)

### Other agent-readable surfaces

- [Platform overview](https://poyo.ai/llms.txt)
- [Documentation index](https://docs.poyo.ai/llms.txt)
- [Full documentation text](https://docs.poyo.ai/llms-full.txt)
- Any other model: `https://poyo.ai/models/<model-id>/llms.txt`
