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.
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
| Version | Model ID |
|---|---|
| Standard | gemini-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
AuthorizationstringheaderrequiredAll requests require a Bearer Token. Get your API Key from the API Key Management Page.
Authorization: Bearer YOUR_API_KEYRequest Parameters
modelstringbodyrequireddefault: gemini-nano-banana-2.1Set to gemini-nano-banana-2.1.
promptstringbodyrequiredText description for image generation or editing.
sizestringbodyOutput image aspect ratio. Supported values:
1:13:2,2:34:3,3:416:9,9:165:4,4:521:91:4,4:11:8,8:1
nintegerbodydefault: 1The output count is fixed at the number 1. Do not use the string "1".
image_urlsstring[]bodyArray 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"]metadataobjectbodyAdditional configuration options.
metadata
resolutionstringbodydefault: 1KOutput image resolution. Supported values: 1K, 2K, 4K. Default: 1K. Use an uppercase K.
Response Fields
idstringTask ID used to query task status and results.
objectstringAlways generation.task.
modelstringModel ID used in the request.
statusstringTask status: queued, in_progress, completed, failed.
progressintegerTask progress as a percentage from 0 to 100.
created_atintegerTask creation time as a Unix timestamp in seconds.
metadataobjectTask 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.