The Nano Banana API lets you generate images from text prompts using Google's Gemini Image models.
Endpoints
- Base URL:
https://api.shopaikey.com - Generate image:
POST /images/google/generations
Authentication
All requests require an API key in the header:
Authorization: Bearer <your-api-key>
Generate Images
Request
Endpoint: POST /images/google/generations
Headers:
Authorization: Bearer <your-api-key>
Content-Type: application/json
Body Parameters:
nano-banana Model
The base model, supports up to 3 reference images.
nano-banana-2 Model
New-generation model, balanced between speed and quality. Supports up to 5 reference images and configurable image size (imageSize).
nano-banana-2.1 Model
An upgraded version of nano-banana-2. Takes the same parameters as nano-banana-2: up to 5 reference images and configurable image size (imageSize).
nano-banana-pro Model
Professional model, supports up to 5 reference images and the highest quality.
Supported image sizes (for nano-banana-2, nano-banana-2.1 and nano-banana-pro):
0.5K: 512x512 (for 1:1 aspect ratio)1K: 1024x1024 (for 1:1 aspect ratio)2K: 2048x2048 (for 1:1 aspect ratio)4K: 4096x4096 (for 1:1 aspect ratio)
Supported aspect ratios (for each image size):
1:1,2:3,3:2,3:4,4:3,4:5,5:4,9:16,16:9,21:9
Request Example - nano-banana-2
curl --location --request POST 'https://api.shopaikey.com/images/google/generations' \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "nano-banana-2",
"prompt": "An astronaut riding a horse on the moon, cyberpunk style",
"size": "1:1",
"imageSize": "1K",
"format": "png"
}'
Request Example - nano-banana-2.1
curl --location --request POST 'https://api.shopaikey.com/images/google/generations' \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "nano-banana-2.1",
"prompt": "Portrait of a girl in the rainy Saigon night, reflected neon lights",
"size": "9:16",
"imageSize": "2K",
"format": "png"
}'
Request Example - nano-banana-pro
curl --location --request POST 'https://api.shopaikey.com/images/google/generations' \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "nano-banana-pro",
"prompt": "A surreal landscape painting with vibrant colors",
"size": "16:9",
"imageSize": "4K",
"format": "png"
}'
JavaScript Example
const response = await fetch('https://api.shopaikey.com/images/google/generations', {
method: 'POST',
headers: {
'Authorization': 'Bearer <your-api-key>',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'nano-banana-2',
prompt: 'A surreal landscape painting with vibrant colors',
size: '16:9',
imageSize: '2K',
format: 'png',
response_format: 'url',
}),
});
const data = await response.json();
console.log('Image URL:', data.data[0].url);
Response
When response_format is "url":
{
"created": 1234567890,
"data": [
{
"url": "https://example.com/image.png"
}
]
}
When response_format is "b64_json":
{
"created": 1234567890,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
}
]
}
Generating Images with Reference Images
You can provide reference images for the model to generate images based on their style or content:
const response = await fetch('https://api.shopaikey.com/images/google/generations', {
method: 'POST',
headers: {
'Authorization': 'Bearer <your-api-key>',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'nano-banana-2',
prompt: 'Create a similar image but with a different theme',
size: '16:9',
imageSize: '2K',
image_urls: [
'https://example.com/reference1.jpg',
'https://example.com/reference2.jpg'
],
}),
});
Model Comparison
Error Handling
The API returns HTTP error codes and error messages in the response:
{
"error": {
"message": "Model and prompt are required"
}
}
Common error codes:
- 400: Invalid request (missing parameters, invalid values, too many reference images)
- 401: Missing or invalid API key
- 500: Server error or model not found
Best Practices
- Prompt Quality: Write clear, detailed prompts for better results
- Aspect Ratio: Choose the aspect ratio appropriate for your use case
- Image Size: With
nano-banana-pro, choose an appropriate image size (2K for most cases, 4K for high quality) - Reference Images: Use high-quality reference images for better results
- Format: Use
pngfor images needing transparency,jpegfor regular images