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

# Gemini Nano Banana 2.1 Official Image Generation

> Gemini Nano Banana 2.1 Official supports text-to-image and image-to-image generation with up to 14 reference images, 1K-4K output, and optional Google Search grounding.

<Note>
  **Note for users in mainland China:** Please use `https://toapis.cn` as the API endpoint (Base URL). Replace `https://toapis.com` with `https://toapis.cn` in the examples in this document.
</Note>

## Version Options

| Version | Reference image limit | Use case |
| - | - | - |
| [Standard](../gemini-nano-banana-2.1/generation) | 14 | Standard text-to-image and edits |
| [VIP](../gemini-nano-banana-2.1/generation) | 14 | Higher availability; use `gemini-nano-banana-2.1-vip` |
| [Official](../gemini-nano-banana-2.1-official/generation) | 14 | When you need native generation parameter control and Google Search grounding |

The reference image count is the total number of input images; it does not represent the number of output images. The versions use different model IDs, so follow the parameters and examples on the corresponding page.

## Current Version

Use `model: "gemini-nano-banana-2.1-official"` to select Official. It supports text-to-image and image-to-image generation or editing with up to 14 reference images and 1K, 2K, or 4K output.
It uses Google Vertex AI and supports native extension parameters such as `temperature`, `topP`, `thinkingConfig`, `safetySettings`, and Google Search `grounding`; see the fields below.
Requests run asynchronously. After submission, use the task ID to query the result.

<Warning>
  `image_urls` accepts image URLs only, not base64 data. Use the [Upload Image endpoint](../../uploads/images) first to obtain an accessible URL.
</Warning>

## Authentication

<ParamField header="Authorization" type="string" required>
  All endpoints require Bearer Token authentication

  Get API Key: Visit the [API Key Management page](https://toapis.com/console/token) to obtain your API Key

  Add to request headers:

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## Request Parameters

<ParamField body="model" type="string" default="gemini-nano-banana-2.1-official" required>
  Image generation model name

  Example: `"gemini-nano-banana-2.1-official"`
</ParamField>

<ParamField body="prompt" type="string" required>
  Text description for image generation
</ParamField>

<ParamField body="size" type="string">
  Image aspect ratio

  Supported formats:

  * `1:1` - Square
  * `3:2` / `2:3`
  * `3:4` / `4:3`
  * `4:5` / `5:4`
  * `9:16` / `16:9`
  * `21:9` / `9:21`
  * `1:4` / `4:1`
  * `1:8` / `8:1`
</ParamField>

<ParamField body="n" type="integer" default={1}>
  Number of images to generate

  Fixed at 1
</ParamField>

<ParamField body="image_urls" type="string[]">
  Reference image URL array for image-to-image generation or editing

  **⚠️ Only URL format is supported (base64 is not supported)**

  * Publicly accessible image URLs (http\:// or https\://)
  * Use the [Upload Image endpoint](../../uploads/images) to upload local images and get URLs

  **Limits:**

  * Maximum 14 images
  * Maximum file size per image: 10MB
  * Supported formats: .jpeg, .jpg, .png, .webp
</ParamField>

<ParamField body="metadata" type="object">
  Vertex AI native extension parameters

  <Expandable title="Show metadata fields">
    <ParamField body="temperature" type="number">
      Generation temperature, controls output randomness

      Range: `0.0` - `2.0`
    </ParamField>

    <ParamField body="topP" type="number">
      Top-P sampling parameter

      Range: `0.0` - `1.0`, default `0.95`
    </ParamField>

    <ParamField body="maxOutputTokens" type="integer">
      Maximum output tokens

      Default `32768`
    </ParamField>

    <ParamField body="resolution" type="string">
      Output image resolution, automatically mapped to Vertex AI native imageSize

      Options: `1K`, `2K`, `4K`, default `1K`
    </ParamField>

    <ParamField body="grounding" type="string" default="none">
      Google Search grounding. When enabled, the model searches Google before generating, and the result may include cited sources in the returned `grounding_metadata`.

      Options:

      * `none` - Disabled (default)
      * `web` - Web search
      * `image` - Image search
      * `web_image` - Web + image search

      Billed per executed search query at \$0.014 per query. A deposit for up to 4 queries is reserved when the request is submitted; unused queries are refunded at settlement.
    </ParamField>

    <ParamField body="personGeneration" type="string">
      Person generation control

      Options:

      * `ALLOW_ALL` - Allow generating all people (including adults and children)
      * `ALLOW_ADULT` - Allow generating adults only
      * `ALLOW_NONE` - Disallow generating people
    </ParamField>

    <ParamField body="imageOutputOptions" type="object">
      Image output format configuration

      <Expandable title="imageOutputOptions fields">
        <ParamField body="mimeType" type="string">
          Output image format

          Options: `image/png`, `image/jpeg`, `image/webp`
        </ParamField>

        <ParamField body="compressionQuality" type="integer">
          Compression quality (JPEG only)
        </ParamField>
      </Expandable>
    </ParamField>

    <ParamField body="thinkingConfig" type="object">
      Thinking mode configuration. When enabled, the model reasons before generating images, improving results for complex scenes

      <Expandable title="thinkingConfig fields">
        <ParamField body="thinkingBudget" type="integer">
          Thinking token budget, controls the depth of model reasoning

          Range: `0` - `24576`, default is determined by the model
        </ParamField>

        <ParamField body="thinkingLevel" type="string">
          Thinking level

          Options: `LOW`, `MEDIUM`, `HIGH`, `MINIMAL`
        </ParamField>
      </Expandable>
    </ParamField>

    <ParamField body="safetySettings" type="array">
      Safety settings array for content safety filtering

      <Expandable title="safetySettings elements">
        <ParamField body="category" type="string">
          Safety category

          Options: `HARM_CATEGORY_HATE_SPEECH`, `HARM_CATEGORY_DANGEROUS_CONTENT`, `HARM_CATEGORY_SEXUALLY_EXPLICIT`, `HARM_CATEGORY_HARASSMENT`
        </ParamField>

        <ParamField body="threshold" type="string">
          Filtering threshold

          Options: `OFF`, `BLOCK_LOW_AND_ABOVE`, `BLOCK_MEDIUM_AND_ABOVE`, `BLOCK_ONLY_HIGH`
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

## Response Fields

<ResponseField name="id" type="string">
  Unique task identifier for querying task status
</ResponseField>

<ResponseField name="object" type="string">
  Object type, always `generation.task`
</ResponseField>

<ResponseField name="model" type="string">
  Model name used
</ResponseField>

<ResponseField name="status" type="string">
  Task status

  * `queued` - Queued for processing
  * `in_progress` - Processing
  * `completed` - Successfully completed
  * `failed` - Failed
</ResponseField>

<ResponseField name="progress" type="integer">
  Task progress percentage (0-100)
</ResponseField>

<ResponseField name="created_at" type="integer">
  Task creation timestamp (Unix timestamp)
</ResponseField>

<ResponseField name="metadata" type="object">
  Task metadata
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://toapis.com/v1/images/generations \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "gemini-nano-banana-2.1-official",
      "prompt": "A futuristic city skyline with neon lights, cyberpunk style",
      "size": "16:9",
      "n": 1,
      "metadata": {
        "temperature": 1.0,
        "topP": 0.95,
        "resolution": "2K",
        "personGeneration": "ALLOW_ALL",
        "thinkingConfig": {
          "thinkingLevel": "HIGH"
        }
      }
    }'
  ```

  ```bash cURL (with Grounding) theme={null}
  curl --request POST \
    --url https://toapis.com/v1/images/generations \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "gemini-nano-banana-2.1-official",
      "prompt": "Generate an infographic about today's A-share market trend",
      "size": "3:4",
      "n": 1,
      "metadata": {
        "resolution": "2K",
        "grounding": "web_image"
      }
    }'
  ```

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

  response = requests.post(
      "https://toapis.com/v1/images/generations",
      headers={
          "Authorization": "Bearer your-ToAPIs-key",
          "Content-Type": "application/json"
      },
      json={
          "model": "gemini-nano-banana-2.1-official",
          "prompt": "A futuristic city skyline with neon lights, cyberpunk style",
          "size": "16:9",
          "n": 1,
          "metadata": {
              "temperature": 1.0,
              "topP": 0.95,
              "resolution": "2K",
              "personGeneration": "ALLOW_ALL",
              "thinkingConfig": {
                  "thinkingLevel": "HIGH"
              }
          }
      }
  )

  task = response.json()
  print(f"Task ID: {task['id']}")
  print(f"Status: {task['status']}")
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://toapis.com/v1/images/generations', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer your-Toapis-key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      model: 'gemini-nano-banana-2.1-official',
      prompt: 'A futuristic city skyline with neon lights, cyberpunk style',
      size: '16:9',
      n: 1,
      metadata: {
        temperature: 1.0,
        topP: 0.95,
        resolution: '2K',
        personGeneration: 'ALLOW_ALL',
        thinkingConfig: {
          thinkingLevel: 'HIGH'
        }
      }
    })
  });

  const task = await response.json();
  console.log(`Task ID: ${task.id}`);
  console.log(`Status: ${task.status}`);
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "task_img_abc123def456",
    "object": "generation.task",
    "model": "gemini-nano-banana-2.1-official",
    "status": "queued",
    "progress": 0,
    "created_at": 1703884800,
    "metadata": {}
  }
  ```
</ResponseExample>

## Query Results

The `id` in the submission response is the task ID. Use the [Image Task Status endpoint](../../tasks/image-status) to retrieve the status and final images.
When `grounding` is enabled, the task result also returns `grounding_metadata` with search queries and cited sources.
Task status queries and [Webhook callbacks](../../webhooks/task-webhooks) follow the standard asynchronous image API conventions.


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