Multimedia

Nano Banana

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:

code
Authorization: Bearer <your-api-key>

Generate Images

Request

Endpoint: POST /images/google/generations

Headers:

code
Authorization: Bearer <your-api-key>
Content-Type: application/json

Body Parameters:

ParameterTypeRequiredDescription
modelstringYesModel to use: nano-banana, nano-banana-2, nano-banana-2.1, or nano-banana-pro
promptstringYesDescription of the image you want to generate
sizestringNoAspect ratio. Default: 1:1. Valid values: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
imageSizestringNoImage size (for nano-banana-2, nano-banana-2.1 and nano-banana-pro): 0.5K, 1K, 2K, 4K. Default: 2K
formatstringNoImage format: png or jpeg. Default: png
response_formatstringNoResponse format: url or b64_json. Default: url
image_urlsarrayNoArray of reference image URLs (max 3 for nano-banana, 5 for nano-banana-2, nano-banana-2.1 and nano-banana-pro)

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

code
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

code
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

code
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

code
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":

code
{
  "created": 1234567890,
  "data": [
    {
      "url": "https://example.com/image.png"
    }
  ]
}

When response_format is "b64_json":

code
{
  "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:

code
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

Featurenano-banananano-banana-2nano-banana-2.1nano-banana-pro
Reference imagesMax 3Max 5Max 5Max 5
Image sizesFixed0.5K, 1K, 2K, 4K0.5K, 1K, 2K, 4K0.5K, 1K, 2K, 4K
QualityGoodVery goodVery goodExcellent
SpeedFastBalancedBalancedModerate

Error Handling

The API returns HTTP error codes and error messages in the response:

code
{
  "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

  1. Prompt Quality: Write clear, detailed prompts for better results
  2. Aspect Ratio: Choose the aspect ratio appropriate for your use case
  3. Image Size: With nano-banana-pro, choose an appropriate image size (2K for most cases, 4K for high quality)
  4. Reference Images: Use high-quality reference images for better results
  5. Format: Use png for images needing transparency, jpeg for regular images