Logo
Logo
API OverviewAuthenticationGenerate Images
API Testing Guide
API Reference

Generate Images

API endpoint for generating images

Endpoint

POST /api/ai/nano-banana/generate

Generate images from text prompts with optional reference images.

Request

Headers

HeaderRequiredDescription
AuthorizationYesBearer token with your API key: Bearer sk-xxxxx
Content-TypeYesapplication/json or multipart/form-data

Body Parameters

Prop

Type

Supported Aspect Ratios

RatioDescriptionUse Case
1:1SquareSocial media posts, profile pictures
2:3PortraitMobile wallpapers
3:2LandscapePhotography style
3:4PortraitProduct images
4:3LandscapePresentations
9:16VerticalStories, TikTok, Reels
16:9WidescreenYouTube thumbnails, desktop wallpapers
21:9Ultra-wideCinematic banners

Response

Success Response (200)

{
  "model": "nano-banana-2-4k",
  "created": 1705123456,
  "images": [
    {
      "url": "https://storage.example.com/generated-image.png"
    }
  ]
}

Response Fields

Prop

Type

Examples

Basic Text-to-Image

curl -X POST https://nano-banana-pro.net/api/ai/nano-banana/generate \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A serene Japanese garden with cherry blossoms, koi pond, and a traditional wooden bridge, golden hour lighting",
    "size": "4k",
    "aspectRatio": "16:9"
  }'
async function generateImage() {
  const response = await fetch('https://nano-banana-pro.net/api/ai/nano-banana/generate', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer sk-your-api-key',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      prompt: 'A serene Japanese garden with cherry blossoms, koi pond, and a traditional wooden bridge, golden hour lighting',
      size: '4k',
      aspectRatio: '16:9',
    }),
  });

  if (!response.ok) {
    throw new Error(`API error: ${response.status}`);
  }

  const data = await response.json();
  console.log('Generated image URL:', data.images[0].url);
  return data;
}
import requests

def generate_image():
    response = requests.post(
        'https://nano-banana-pro.net/api/ai/nano-banana/generate',
        headers={
            'Authorization': 'Bearer sk-your-api-key',
            'Content-Type': 'application/json',
        },
        json={
            'prompt': 'A serene Japanese garden with cherry blossoms, koi pond, and a traditional wooden bridge, golden hour lighting',
            'size': '4k',
            'aspectRatio': '16:9',
        }
    )

    response.raise_for_status()
    data = response.json()
    print('Generated image URL:', data['images'][0]['url'])
    return data

Image-to-Image with Reference URL

Use a reference image to guide the generation:

curl -X POST https://nano-banana-pro.net/api/ai/nano-banana/generate \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Transform this image into a watercolor painting style",
    "image": "https://example.com/my-photo.jpg",
    "size": "2k"
  }'
const response = await fetch('https://nano-banana-pro.net/api/ai/nano-banana/generate', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk-your-api-key',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    prompt: 'Transform this image into a watercolor painting style',
    image: 'https://example.com/my-photo.jpg',
    size: '2k',
  }),
});
response = requests.post(
    'https://nano-banana-pro.net/api/ai/nano-banana/generate',
    headers={
        'Authorization': 'Bearer sk-your-api-key',
        'Content-Type': 'application/json',
    },
    json={
        'prompt': 'Transform this image into a watercolor painting style',
        'image': 'https://example.com/my-photo.jpg',
        'size': '2k',
    }
)

Multiple Reference Images

Combine multiple images for complex compositions:

{
  "prompt": "Combine these images into a cohesive landscape scene",
  "image": [
    "https://example.com/mountains.jpg",
    "https://example.com/lake.jpg",
    "https://example.com/sunset.jpg"
  ],
  "size": "4k",
  "aspectRatio": "21:9"
}

Upload Image via Multipart Form

For uploading local images:

curl -X POST https://nano-banana-pro.net/api/ai/nano-banana/generate \
  -H "Authorization: Bearer sk-your-api-key" \
  -F "prompt=Make this photo look like a vintage film photograph" \
  -F "size=2k" \
  -F "image=@/path/to/your/image.jpg"
const formData = new FormData();
formData.append('prompt', 'Make this photo look like a vintage film photograph');
formData.append('size', '2k');
formData.append('image', fileInput.files[0]); // File from input element

const response = await fetch('https://nano-banana-pro.net/api/ai/nano-banana/generate', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk-your-api-key',
    // Don't set Content-Type - browser will set it with boundary
  },
  body: formData,
});
with open('/path/to/your/image.jpg', 'rb') as f:
    response = requests.post(
        'https://nano-banana-pro.net/api/ai/nano-banana/generate',
        headers={
            'Authorization': 'Bearer sk-your-api-key',
        },
        data={
            'prompt': 'Make this photo look like a vintage film photograph',
            'size': '2k',
        },
        files={
            'image': ('image.jpg', f, 'image/jpeg'),
        }
    )

Error Responses

StatusErrorDescription
400Bad RequestInvalid request parameters
401UnauthorizedMissing or invalid API key
402Payment RequiredInsufficient credits
500Internal Server ErrorGeneration failed

Error Response Format

{
  "error": "Error message describing what went wrong"
}

Common Errors

Plan Limits

FeatureFreeStandardPro
Max reference images3814
Concurrent generations1510
Max image size2.5MB2.5MB2.5MB
4K generation✗✓✓
API access✗✓✓

Tips for Better Results

Write detailed prompts

Be specific about what you want. Include details about style, lighting, composition, and mood.

// Good
"A cozy coffee shop interior with warm lighting, exposed brick walls,
vintage wooden furniture, steam rising from cups, morning sunlight
through large windows, photorealistic, 4K quality"

// Less effective
"coffee shop"

Use style modifiers

Add quality and style keywords to improve results:

  • 4K quality, highly detailed, photorealistic
  • cinematic lighting, golden hour, soft shadows
  • oil painting style, watercolor, digital art

Choose appropriate aspect ratios

Match your aspect ratio to your intended use:

  • Social posts: 1:1
  • Phone wallpapers: 9:16
  • Desktop wallpapers: 16:9
  • Cinematic: 21:9

Authentication

How to authenticate with the NB Pro API

API Testing Guide

Local testing examples for the image generation API

Table of Contents

Endpoint
Request
Headers
Body Parameters
Supported Aspect Ratios
Response
Success Response (200)
Response Fields
Examples
Basic Text-to-Image
Image-to-Image with Reference URL
Multiple Reference Images
Upload Image via Multipart Form
Error Responses
Error Response Format
Common Errors
Plan Limits
Tips for Better Results
Write detailed prompts
Use style modifiers
Choose appropriate aspect ratios