Nano Banana Pro API Guide: Generate & Edit Images in 5 Lines of Python Code (5 Examples Use Cases)

Nano Banana Pro API Guide

TL;DR

Google’s latest image generation model, Nano Banana Pro, lets you create, edit, and transform images with simple text prompts. This guide shows you the raw API approach, then how SimplerLLM reduces complexity by 70% and lets you switch providers instantly. You’ll learn image generation, editing, and 5 production-ready use cases (YouTube thumbnails, product photography, sketch-to-realistic, landing page redesigns) that solo builders can ship today!

Hasan aboul hasan with nano banana pro generated image

What You’ll Build with Nano Banana Pro

By the end of this guide, you’ll generate:

  • Professional product photos from casual snapshots
  • Click-worthy YouTube thumbnails with consistent characters
  • Realistic images from hand-drawn sketches
  • Landing page mockups from existing designs
  • Any image you can describe

Why Nano Banana Pro Matters

Nano Banana Pro is Google’s latest image generation model.

If you’re building image generation tools, search engines are flooded with outdated Gemini tutorials. This is the current guide for the model builders are actually using in production.

Current Model name: gemini-3-pro-image-preview

The Raw Gemini API (For Purists)

If you want pure Python with zero dependencies except google-genai package, here’s the minimal code for Nano Banana Pro:

Install & Setup

pip install google-genai

Get your API key: https://aistudio.google.com/apikey

Generate an Image with Nano Banana Pro (Bare Bones)

import google.genai as genai
from google.genai import types

client = genai.Client(api_key="YOUR_API_KEY")

# Generate image with Nano Banana Pro
contents = [
    types.Content(
        role="user",
        parts=[types.Part.from_text(text="A serene mountain landscape")]
    )
]

config = types.GenerateContentConfig(
    response_modalities=["IMAGE"],
    temperature=1.0
)

# Stream and save
image_data = None
for chunk in client.models.generate_content_stream(
    model="gemini-3-pro-image-preview",  # Nano Banana Pro model
    contents=contents,
    config=config
):
    if chunk.candidates:
        for part in chunk.candidates[0].content.parts:
            if hasattr(part, 'inline_data'):
                image_data = part.inline_data.data

with open("output.png", 'wb') as f:
    f.write(image_data)

Edit an Image with Nano Banana Pro (Bare Bones)

# Load image to edit
with open("input.png", 'rb') as f:
    image_bytes = f.read()

contents = [
    types.Content(
        role="user",
        parts=[
            types.Part.from_bytes(data=image_bytes, mime_type='image/png'),
            types.Part.from_text(text="Add a lake in the foreground")
        ]
    )
]

config = types.GenerateContentConfig(
    response_modalities=["IMAGE"],
    temperature=0.8
)

# Generate with Nano Banana Pro
edited_data = None
for chunk in client.models.generate_content_stream(
    model="gemini-3-pro-image-preview",  # Nano Banana Pro
    contents=contents,
    config=config
):
    if chunk.candidates:
        for part in chunk.candidates[0].content.parts:
            if hasattr(part, 'inline_data'):
                edited_data = part.inline_data.data

with open("edited.png", 'wb') as f:
    f.write(edited_data)

This works. But you’re writing boilerplate for every image operation. And if Google changes their API tomorrow? You rewrite everything ???

Why SimplerLLM Changes Everything

SimplerLLM wraps complex APIs into 5-line functions. Here’s what you gain:

1. Provider Flexibility

Switch from Gemini to OpenAI to Stability AI by changing ONE parameter:

# Nano Banana Pro today
img_gen = ImageGenerator.create(provider=ImageProvider.GOOGLE_GEMINI)

# OpenAI tomorrow (if pricing changes)
img_gen = ImageGenerator.create(provider=ImageProvider.OPENAI)

# Your code stays identical

2. Zero Boilerplate

Raw API: 25+ lines per image operation SimplerLLM: 5 lines

3. Production-Ready Features

  • Automatic error handling
  • Reference image support (character consistency)
  • Multiple output formats (bytes, file, base64)
  • Size presets (square, horizontal, vertical)

Install SimplerLLM:

pip install SimplerLLM

Set your API key:

export GEMINI_API_KEY="your-key-here"

Deep Dive: Image Generation with Nano Banana Pro

Let’s generate a professional image from scratch using Nano Banana Pro.

Basic Generation

from SimplerLLM import ImageGenerator, ImageProvider, ImageSize

# Create generator instance (one-time setup)
img_gen = ImageGenerator.create(provider=ImageProvider.GOOGLE_GEMINI)

# Generate with Nano Banana Pro
output_path = img_gen.generate_image(
    prompt="A futuristic city at sunset with flying cars",
    size=ImageSize.HORIZONTAL,
    output_format="file",
    model="gemini-3-pro-image-preview",  # Nano Banana Pro
    output_path="futuristic_city.png"
)

print(f"Image saved: {output_path}")

What’s happening:

  • model="gemini-3-pro-image-preview": Uses Nano Banana Pro
  • ImageSize.HORIZONTAL: 16:9 aspect ratio (also: SQUARE, VERTICAL)
  • output_format="file": Saves directly (also: "bytes" for in-memory)
  • output_path: Where to save your image

AI generated futuristic city at sunset with flying cars and neon lights created using Google Nano Banana Pro image generation API and SimplerLLM Python library

Advanced: Character Consistency with Reference Images

Nano Banana Pro excels at maintaining character consistency across images. Use reference images:

# Step 1: Generate character reference with Nano Banana Pro
character_ref = img_gen.generate_image(
    prompt="Portrait of a young wizard with blue robes and pointed hat",
    size=ImageSize.SQUARE,
    output_format="file",
    model="gemini-3-pro-image-preview",  # Nano Banana Pro
    output_path="wizard_reference.png"
)

# Step 2: Use reference for consistent character in new scenes
img_gen.generate_image(
    prompt="The same character casting a spell in a magical forest",
    reference_images=[character_ref],  # ← Character consistency
    size=ImageSize.HORIZONTAL,
    output_format="file",
    model="gemini-3-pro-image-preview",  # Nano Banana Pro
    output_path="wizard_in_forest.png"
)
Character consistency in AI image generation using Nano Banana Pro showing same wizard character in different scenes using reference images with Google Gemini API

Pro Tip: You can pass multiple reference images for scenes with multiple characters. Nano Banana Pro handles this seamlessly.

Deep Dive: Image Editing with Nano Banana Pro

Transform existing images with text instructions using Nano Banana Pro.

Real Example: Product Photography Enhancement

Take a casual product photo and turn it into a studio-quality shot:

from SimplerLLM import ImageGenerator, ImageProvider, ImageSize

img_gen = ImageGenerator.create(provider=ImageProvider.GOOGLE_GEMINI)

# Edit with Nano Banana Pro for studio quality
studio_shot = img_gen.edit_image(
    image_source="casual_watch_photo.jpg",
    edit_prompt="""Transform into professional studio shot:
    - Professional three-point lighting
    - Clean white background
    - Remove distractions
    - Enhance product details and colors
    - Add natural shadows for depth
    - Make it look like a luxury advertisement""",
    size=ImageSize.HORIZONTAL,
    output_format="file",
    model="gemini-3-pro-image-preview",  # Nano Banana Pro
    output_path="studio_watch.png"
)
Before and after product photography enhancement using Nano Banana Pro AI image editing

What makes Nano Banana Pro powerful for this:

  • No Photoshop skills required
  • Consistent results across products
  • Scale to hundreds of products
  • Perfect for e-commerce

Another Example: Sky Replacement

edited = img_gen.edit_image(
    image_source="city_daytime.png",
    edit_prompt="Change the sky to a starry night with full moon",
    size=ImageSize.HORIZONTAL,
    output_format="file",
    model="gemini-3-pro-image-preview",  # Nano Banana Pro
    output_path="city_night.png"
)

4 More Production-Ready Use Cases with Nano Banana Pro

1. YouTube Thumbnail Generator

High-CTR thumbnails with consistent personal branding:

img_gen.generate_image(
    prompt="""Professional YouTube thumbnail:
    - Person with excited, enthusiastic expression
    - Center-left positioning (space for text overlay)
    - Dramatic lighting with high contrast
    - Vibrant colors (warm vs cool tones)
    - Dynamic gradient background
    - Optimized for mobile viewing""",
    reference_images=["person_reference.jpg"],
    size=ImageSize.HORIZONTAL,
    output_format="file",
    model="gemini-3-pro-image-preview",  # Nano Banana Pro
    output_path="youtube_thumbnail.png"
)

Use Nano Banana Pro for:

  • Consistent branding across videos
  • A/B testing thumbnail variations
  • Multiple videos per day (scale!)
AI generated YouTube thumbnail using Nano Banana Pro optimized for high click-through rate with dramatic lighting and mobile-friendly design

2. Sketch to Realistic Image

Turn hand-drawn concepts into photorealistic images with Nano Banana Pro:

img_gen.generate_image(
    prompt="""Transform hand-drawn sketch into photorealistic photograph:
    - Maintain exact composition from sketch
    - Realistic details and textures
    - Professional lighting and shadows
    - Natural, vibrant colors
    - High-definition quality""",
    reference_images=["sketch.png"],
    size=ImageSize.HORIZONTAL,
    output_format="file",
    model="gemini-3-pro-image-preview",  # Nano Banana Pro
    output_path="realistic_from_sketch.png"
)

Use this for:

  • Product concept visualization
  • Architectural mockups
  • UI/UX design exploration
  • Client presentations
Hand-drawn sketch transformed into photorealistic image using Nano Banana Pro AI image generation showing concept visualization workflow

3. Landing Page Redesign

Reimagine landing pages with modern design trends using Nano Banana Pro:

img_gen.generate_image(
    prompt="""Reimagine this landing page with modern web design:
    - Contemporary UI/UX principles
    - Vibrant, sophisticated color palette
    - Clean typography with visual hierarchy
    - Eye-catching hero section
    - Modern design elements (glassmorphism, shadows)
    - Generous whitespace
    - Clear call-to-action flow
    - High conversion-rate design""",
    reference_images=["current_landing.jpg"],
    size=ImageSize.HORIZONTAL,
    output_format="file",
    model="gemini-3-pro-image-preview",  # Nano Banana Pro
    output_path="redesigned_landing.png"
)

Use this for:

  • Client presentations (show “what if” designs)
  • A/B testing variations
  • Design inspiration
  • Rapid prototyping

Landing page redesign comparison using Nano Banana Pro showing modern UI/UX transformation for web design prototyping

4. Product to Studio Quality

Already covered in detail above, but the key insight:

Change ONE line to apply Nano Banana Pro to different products:

image_source="watch.jpg"  # Change to: "phone.jpg", "shoes.jpg", etc.

Same prompt works for all product types.

Production Tips for Solo Builders Using Nano Banana Pro

1. Switch Providers Without Rewriting Code

Building a SaaS? Don’t lock yourself to one provider:

# Today: Use Nano Banana Pro
img_gen = ImageGenerator.create(provider=ImageProvider.GOOGLE_GEMINI)

# Tomorrow: Scale to OpenAI (if needed)
img_gen = ImageGenerator.create(provider=ImageProvider.OPENAI)

# Next week: Try Stability AI
img_gen = ImageGenerator.create(provider=ImageProvider.STABILITY_AI)

# Your business logic stays identical
output = img_gen.generate_image(
    prompt="...", 
    model="gemini-3-pro-image-preview",  # Nano Banana Pro
    ...
)

Why this matters:

  • Provider pricing changes? Switch in 1 minute
  • API goes down? Instant failover
  • Better model releases? Test without refactoring

2. Handle Errors Gracefully

try:
    output = img_gen.generate_image(
        prompt="Your prompt",
        size=ImageSize.HORIZONTAL,
        output_format="file",
        model="gemini-3-pro-image-preview",  # Nano Banana Pro
        output_path="output.png"
    )
except Exception as e:
    print(f"Nano Banana Pro generation failed: {e}")
    # Fallback logic or retry

FAQ: Nano Banana Pro Image Generation

What is Nano Banana Pro?

Nano Banana Pro is Google’s latest image generation model (technical name: gemini-3-pro-image-preview). It’s the current production-ready model for generating and editing images through the Gemini API.

1- How much does Nano Banana Pro image generation cost?

it costs around $0.134 per 1K/2K image and $0.24 per 4K image, check Google Docs for more info

2- What image sizes does Nano Banana Pro support in SimplerLLM?

SimplerLLM provides three presets: ImageSize.SQUARE (1:1), ImageSize.HORIZONTAL (16:9), and ImageSize.VERTICAL (9:16). These cover most use cases from social media to YouTube to product photos.

3- How do I maintain character consistency with Nano Banana Pro?

Use the reference_images parameter when generating new images. Pass the path to your character reference image, and Nano Banana Pro will maintain visual consistency across generations.

4- Can I edit images with Nano Banana Pro without SimplerLLM?

Yes, the raw Gemini API supports editing with Nano Banana Pro. SimplerLLM just reduces the boilerplate from ~25 lines to 5 lines per operation.

5- How is Nano Banana Pro different from other Gemini models?

Nano Banana Pro (gemini-3-pro-image-preview) is the latest production model specifically designed for high-quality image generation and editing.

Resources to Level Up

SimplerLLM Deep Dive

Want to build more with LLMs? SimplerLLM is an open-source Python package that simplifies ALL LLM interactions (not just images). Perfect for solo builders shipping fast.

👉 GitHub: SimplerLLM Repository 👉 PyPI: pip install SimplerLLM

Learn to Build & Ship Solo

Building alone?

What Will You Build with Nano Banana Pro?

Image generation unlocks endless possibilities:

  • SaaS product with custom branding
  • E-commerce with studio-quality photos
  • Content creation tools
  • Marketing automation
  • Design services

Nano Banana Pro is the latest model. The API is simple. The code is 5 lines. The only limit is your imagination.

Related Articles