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

# Gemini Nano Banana 2.1

> Generate and edit images with Google Gemini Nano Banana 2.1 through the AnyFast native Gemini API.

Gemini Nano Banana 2.1 is Google's stable, high-efficiency image generation and conversational editing model. Use the model ID `gemini-nano-banana-2.1` with the native Gemini `GenerateContent` endpoint.

<Info>
  Google released `gemini-nano-banana-2.1` as a generally available model on October 6, 2026. Google recommends it for new projects that previously used `gemini-3.1-flash-image`.
</Info>

## Model specifications

| Property | Value |
| - | - |
| Model ID | `gemini-nano-banana-2.1` |
| Endpoint | `POST /v1beta/models/gemini-nano-banana-2.1:generateContent` |
| Input | Text, image, video, PDF |
| Output | Image and text |
| Input token limit | 131,072 |
| Output token limit | 32,768 |
| Output resolution | `1K`, `2K`, `4K`; default `1K` |
| Reference images | Up to 14 total; up to 4 characters and 10 objects for high-fidelity consistency |
| Thinking levels | `minimal`, `medium`, `high`; default `medium` |

## Key capabilities

* Generate an image from a text prompt.
* Edit an existing image through a conversational instruction.
* Combine up to 14 reference images in one request.
* Preserve character and object appearance across iterative edits.
* Generate wide and panoramic layouts, including `1:4`, `4:1`, `1:8`, and `8:1`.
* Produce text-heavy visuals such as infographics, menus, and diagrams.

All generated images contain Google's SynthID watermark.

## Request examples

<Tabs sync={false}>
  <Tab title="Text to image">
    Use `responseModalities` to request an image, then set the aspect ratio and resolution under `responseFormat.image`.

    ```bash cURL theme={null}
    curl "https://www.anyfast.ai/v1beta/models/gemini-nano-banana-2.1:generateContent?key=YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "contents": [{
          "role": "user",
          "parts": [{
            "text": "Create a clean 16:9 product poster for a translucent blue mechanical keyboard on a dark studio background. Include the headline: TYPE FASTER."
          }]
        }],
        "generationConfig": {
          "responseModalities": ["TEXT", "IMAGE"],
          "responseFormat": {
            "image": {
              "aspectRatio": "16:9",
              "imageSize": "2K"
            }
          }
        }
      }'
    ```
  </Tab>

  <Tab title="Image editing">
    Add a Base64-encoded reference image as an `inline_data` part next to the editing instruction.

    ```bash cURL theme={null}
    curl "https://www.anyfast.ai/v1beta/models/gemini-nano-banana-2.1:generateContent?key=YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "contents": [{
          "role": "user",
          "parts": [
            {
              "text": "Keep the product unchanged, replace the background with a warm wooden desk, and add soft morning light from the left."
            },
            {
              "inline_data": {
                "mime_type": "image/png",
                "data": "YOUR_BASE64_IMAGE_DATA"
              }
            }
          ]
        }],
        "generationConfig": {
          "responseModalities": ["IMAGE"],
          "responseFormat": {
            "image": {
              "aspectRatio": "4:3",
              "imageSize": "2K"
            }
          }
        }
      }'
    ```
  </Tab>

  <Tab title="Thinking level">
    Use `thinkingConfig.thinkingLevel` to balance latency and image quality. The default is `medium`.

    ```bash cURL theme={null}
    curl "https://www.anyfast.ai/v1beta/models/gemini-nano-banana-2.1:generateContent?key=YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "contents": [{
          "parts": [{
            "text": "Design a technically accurate exploded-view infographic of a mirrorless camera with concise English labels."
          }]
        }],
        "generationConfig": {
          "responseModalities": ["IMAGE"],
          "thinkingConfig": {
            "thinkingLevel": "high"
          },
          "responseFormat": {
            "image": {
              "aspectRatio": "4:3",
              "imageSize": "4K"
            }
          }
        }
      }'
    ```
  </Tab>
</Tabs>

## Read the generated image

The response can contain text parts and image parts. Decode `inlineData.data` from Base64 and save it using the MIME type returned in `inlineData.mimeType`.

```python Python theme={null}
import base64
import requests

response = requests.post(
    "https://www.anyfast.ai/v1beta/models/gemini-nano-banana-2.1:generateContent",
    params={"key": "YOUR_API_KEY"},
    json={
        "contents": [{
            "parts": [{"text": "Create a minimal isometric illustration of a green data center."}]
        }],
        "generationConfig": {
            "responseModalities": ["TEXT", "IMAGE"],
            "responseFormat": {
                "image": {"aspectRatio": "16:9", "imageSize": "1K"}
            },
        },
    },
)
response.raise_for_status()

for part in response.json()["candidates"][0]["content"]["parts"]:
    if "text" in part:
        print(part["text"])
    if "inlineData" in part:
        with open("output.png", "wb") as image_file:
            image_file.write(base64.b64decode(part["inlineData"]["data"]))
```

## Image configuration

| Field | Values | Notes |
| - | - | - |
| `generationConfig.responseModalities` | `IMAGE`, or `TEXT` and `IMAGE` | Defaults to text and image output. |
| `generationConfig.responseFormat.image.imageSize` | `1K`, `2K`, `4K` | Default: `1K`. Nano Banana 2.1 does not support `512`. |
| `generationConfig.responseFormat.image.aspectRatio` | `1:1`, `1:4`, `1:8`, `2:3`, `3:2`, `3:4`, `4:1`, `4:3`, `4:5`, `5:4`, `8:1`, `9:16`, `16:9`, `21:9` | Without an input image, the default is `1:1`; editing requests normally follow the input image unless overridden. |
| `generationConfig.thinkingConfig.thinkingLevel` | `minimal`, `medium`, `high` | Default: `medium`. Thinking tokens are billed even when thoughts are not returned. |
| `generationConfig.thinkingConfig.includeThoughts` | boolean | When `true`, thought parts may be included in the response. Do not treat them as the final image or answer. |

<Warning>
  Do not send `seed`, `topK`, `topP`, `temperature`, or `logprobs`. Google documents these parameters as unsupported for Nano Banana 2.1 and rejects requests that include them.
</Warning>

## Input guidance

* Put text instructions and reference images in the same `parts` array.
* Use `inline_data` for Base64 content and `file_data` for an uploaded file URI.
* Supported image MIME types include PNG, JPEG, WebP, HEIC, and HEIF.
* The model accepts up to 14 reference images, but character consistency is optimized for up to 4 characters and object fidelity for up to 10 objects.
* Video and PDF inputs consume the same 131,072-token context window.

For text inside an image, write the exact required wording in the prompt and describe its placement, type style, and hierarchy.

<Card title="Gemini Nano Banana 2.1 API Reference" icon="code" href="/api-reference/model-api/google/gemini-nano-banana-2-1">
  View the request and response schema for native Gemini image generation.
</Card>

Sources: [Gemini Nano Banana 2.1 model page](https://ai.google.dev/gemini-api/docs/models/gemini-nano-banana-2.1), [Google image generation guide](https://ai.google.dev/gemini-api/docs/generate-content/image-generation), and [Google Cloud model specifications](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/nano-banana-2-1).

<script src="/public/feedback.js" />


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.