ToAPIsToAPIs
Gemini Nano Banana 2.1

Gemini Nano Banana 2.1 Image Generation

Generate and edit images with Gemini Nano Banana 2.1 using up to 14 reference images and 1K, 2K, or 4K resolution.

POST
/v1/images/generations

Note for users in mainland China: Use https://toapis.cn as the Base URL. Replace https://toapis.com with https://toapis.cn in the examples below.

Model Selection

VersionModel ID
Standardgemini-nano-banana-2.1

Text-to-image generation and image editing run as asynchronous tasks. After a successful submission, use the returned task ID to query the result.

image_urls only accepts publicly accessible image URLs, not base64 data. Use the Upload Image API to upload local images and obtain URLs first.

Authentication

Authorizationstringheaderrequired

All requests require a Bearer Token. Get your API Key from the API Key Management Page.

Authorization: Bearer YOUR_API_KEY

Request Parameters

modelstringbodyrequireddefault: gemini-nano-banana-2.1

Set to gemini-nano-banana-2.1.

promptstringbodyrequired

Text description for image generation or editing.

sizestringbody

Output image aspect ratio. Supported values:

  • 1:1
  • 3:2, 2:3
  • 4:3, 3:4
  • 16:9, 9:16
  • 5:4, 4:5
  • 21:9
  • 1:4, 4:1
  • 1:8, 8:1
nintegerbodydefault: 1

The output count is fixed at the number 1. Do not use the string "1".

image_urlsstring[]body

Array of reference image URL strings for image-to-image generation or editing. Maximum 14 images. Each URL must be publicly accessible. The reference image count is not the output image count.

Maximum 10MB per image. Supported formats: .jpeg, .jpg, .png, .webp.

["https://example.com/photo.jpg"]
metadataobjectbody

Additional configuration options.

metadata
resolutionstringbodydefault: 1K

Output image resolution. Supported values: 1K, 2K, 4K. Default: 1K. Use an uppercase K.

Response Fields

idstring

Task ID used to query task status and results.

objectstring

Always generation.task.

modelstring

Model ID used in the request.

statusstring

Task status: queued, in_progress, completed, failed.

progressinteger

Task progress as a percentage from 0 to 100.

created_atinteger

Task creation time as a Unix timestamp in seconds.

metadataobject

Task metadata.

requestExample

curl --request POST \
  --url https://toapis.com/v1/images/generations \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gemini-nano-banana-2.1",
  "prompt": "A cyberpunk city at night with flickering neon lights",
  "size": "16:9",
  "n": 1,
  "metadata": {
    "resolution": "2K"
  }
}'
curl --request POST \
  --url https://toapis.com/v1/images/generations \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gemini-nano-banana-2.1",
  "prompt": "Transform this photo into a watercolor painting",
  "size": "1:1",
  "n": 1,
  "image_urls": [
    "https://example.com/photo.jpg"
  ],
  "metadata": {
    "resolution": "2K"
  }
}'
import requests

response = requests.post(
    "https://toapis.com/v1/images/generations",
    headers={
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json"
    },
    json={
        "model": "gemini-nano-banana-2.1",
        "prompt": "A cyberpunk city at night with flickering neon lights",
        "size": "16:9",
        "n": 1,
        "metadata": {
            "resolution": "2K"
        }
    }
)
response.raise_for_status()
task = response.json()
print(task["id"])
const response = await fetch('https://toapis.com/v1/images/generations', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "model": "gemini-nano-banana-2.1",
    "prompt": "A cyberpunk city at night with flickering neon lights",
    "size": "16:9",
    "n": 1,
    "metadata": {
      "resolution": "2K"
    }
  })
});

if (!response.ok) {
  throw new Error(await response.text());
}
const task = await response.json();
console.log(task.id);

responseExample

{
  "id": "task_img_abc123def456",
  "object": "generation.task",
  "model": "gemini-nano-banana-2.1",
  "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 API to retrieve task status and final images. See Task Webhooks for asynchronous notifications.