ToAPIsToAPIs
Gemini Nano Banana 2.1

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.

POST
/v1/images/generations

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.

Version Options

VersionReference image limitUse case
Standard14Standard text-to-image and edits
Official14When 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.

image_urls accepts image URLs only, not base64 data. Use the Upload Image endpoint first to obtain an accessible URL.

Authentication

Authorizationstringheaderrequired

All endpoints require Bearer Token authentication

Get API Key: Visit the API Key Management page to obtain your API Key

Add to request headers:

Authorization: Bearer YOUR_API_KEY

Request Parameters

modelstringbodyrequireddefault: gemini-nano-banana-2.1-official

Image generation model name

Example: "gemini-nano-banana-2.1-official"

promptstringbodyrequired

Text description for image generation

sizestringbody

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
nintegerbodydefault: 1

Number of images to generate

Fixed at 1

image_urlsstring[]body

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 to upload local images and get URLs

Limits:

  • Maximum 14 images
  • Maximum file size per image: 10MB
  • Supported formats: .jpeg, .jpg, .png, .webp
metadataobjectbody

Vertex AI native extension parameters

Show metadata fields
temperaturenumberbody

Generation temperature, controls output randomness

Range: 0.0 - 2.0

topPnumberbody

Top-P sampling parameter

Range: 0.0 - 1.0, default 0.95

maxOutputTokensintegerbody

Maximum output tokens

Default 32768

resolutionstringbody

Output image resolution, automatically mapped to Vertex AI native imageSize

Options: 1K, 2K, 4K, default 1K

groundingstringbodydefault: 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.

personGenerationstringbody

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
imageOutputOptionsobjectbody

Image output format configuration

imageOutputOptions fields
mimeTypestringbody

Output image format

Options: image/png, image/jpeg, image/webp

compressionQualityintegerbody

Compression quality (JPEG only)

thinkingConfigobjectbody

Thinking mode configuration. When enabled, the model reasons before generating images, improving results for complex scenes

thinkingConfig fields
thinkingBudgetintegerbody

Thinking token budget, controls the depth of model reasoning

Range: 0 - 24576, default is determined by the model

thinkingLevelstringbody

Thinking level

Options: LOW, MEDIUM, HIGH, MINIMAL

safetySettingsarraybody

Safety settings array for content safety filtering

safetySettings elements
categorystringbody

Safety category

Options: HARM_CATEGORY_HATE_SPEECH, HARM_CATEGORY_DANGEROUS_CONTENT, HARM_CATEGORY_SEXUALLY_EXPLICIT, HARM_CATEGORY_HARASSMENT

thresholdstringbody

Filtering threshold

Options: OFF, BLOCK_LOW_AND_ABOVE, BLOCK_MEDIUM_AND_ABOVE, BLOCK_ONLY_HIGH

Response Fields

idstring

Unique task identifier for querying task status

objectstring

Object type, always generation.task

modelstring

Model name used

statusstring

Task status

  • queued - Queued for processing
  • in_progress - Processing
  • completed - Successfully completed
  • failed - Failed
progressinteger

Task progress percentage (0-100)

created_atinteger

Task creation timestamp (Unix timestamp)

metadataobject

Task metadata

requestExample

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"
      }
    }
  }'
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"
    }
  }'
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']}")
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}`);

responseExample

{
  "id": "task_img_abc123def456",
  "object": "generation.task",
  "model": "gemini-nano-banana-2.1-official",
  "status": "queued",
  "progress": 0,
  "created_at": 1703884800,
  "metadata": {}
}

Query Results

The id in the submission response is the task ID. Use the Image Task Status endpoint 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 follow the standard asynchronous image API conventions.