Back to Tutorials
Beginner6 min readUpdated: 11/13/2025

Getting Started with Nano Banana

Learn the basics of Google Gemini 2.5 Flash Image (Nano Banana) and generate your first AI image

basicssetupquickstart

Getting Started with Nano Banana

Welcome to the world of AI image generation! This tutorial will guide you through the basics of Nano Banana (officially known as Gemini 2.5 Flash Image), Google's powerful image generation and editing model.

What is Nano Banana?

Nano Banana is Google DeepMind's AI-powered image generation and editing model, part of the Gemini family. It allows you to:

  • Generate images from text descriptions (prompts)
  • Edit existing images with natural language instructions
  • Maintain character consistency across multiple generations
  • Blend multiple images into cohesive compositions

Key Features

  • ✨ High-quality output: State-of-the-art image generation
  • šŸŽÆ Precise control: Detailed prompt understanding
  • šŸ”„ Character consistency: Keep subjects consistent across images
  • šŸŽØ Natural editing: Edit images using simple text commands
  • šŸ”’ SynthID watermark: All images include invisible watermarks

Prerequisites

Before you begin, you'll need:

  1. A Google Account - To access Google AI Studio
  2. Google Gemini API Key - Free tier available
  3. Basic understanding of REST APIs (helpful but not required)

Step 1: Get Your API Key

Follow these steps to obtain your free API key:

1.1 Visit Google AI Studio

Navigate to https://ai.google.dev/ and sign in with your Google account.

1.2 Create API Key

  1. Click on "Get API Key" button
  2. Select or create a Google Cloud project
  3. Click "Create API key"
  4. Copy and save your API key securely

Important: Keep your API key secret! Never commit it to public repositories or share it publicly.

1.3 Set Up Environment Variables

Create a .env.local file in your project:

GOOGLE_GEMINI_API_KEY=your_api_key_here

Step 2: Your First Image Generation

Let's generate your first image using Nano Banana!

Using the Playground

The easiest way to get started is using our Playground:

  1. Navigate to the Playground
  2. Enter a prompt: "a serene mountain landscape at sunset"
  3. Click Generate
  4. Watch your image come to life!

Using the API

For developers, here's how to make your first API call:

// Install the SDK
// npm install @google/generative-ai

import { GoogleGenerativeAI } from "@google/generative-ai";

// Initialize the client
const genAI = new GoogleGenerativeAI(process.env.GOOGLE_GEMINI_API_KEY);

// Get the model
const model = genAI.getGenerativeModel({
  model: "gemini-2.5-flash"
});

// Generate an image
const prompt = "a serene mountain landscape at sunset";
const result = await model.generateContent({
  contents: [{
    role: "user",
    parts: [{ text: `Generate an image: ${prompt}` }]
  }]
});

console.log(result);

Python Example

import google.generativeai as genai
import os

# Configure the API
genai.configure(api_key=os.environ["GOOGLE_GEMINI_API_KEY"])

# Get the model
model = genai.GenerativeModel('gemini-2.5-flash')

# Generate an image
prompt = "a serene mountain landscape at sunset"
response = model.generate_content(f"Generate an image: {prompt}")

print(response)

Step 3: Understanding Prompts

The prompt is your text description of what you want to generate. Good prompts are:

Descriptive

āŒ "a cat"
āœ… "a fluffy orange tabby cat wearing tiny sunglasses, sitting on a beach"

Specific About Style

āŒ "a house"
āœ… "a modern minimalist house, glass facade, surrounded by pine trees, architectural photography"

Detail-Oriented

āŒ "food"
āœ… "gourmet sushi platter, fresh salmon and tuna, garnished with microgreens, professional food photography, natural lighting"

Step 4: Basic Parameters

When generating images, you can control several parameters:

Aspect Ratio

Choose from common aspect ratios:

  • 1:1 - Square (default)
  • 16:9 - Landscape
  • 9:16 - Portrait
  • 4:3 - Standard photo
{
  prompt: "your prompt here",
  aspectRatio: "16:9"
}

Number of Images

Generate multiple variations:

{
  prompt: "your prompt here",
  numberOfImages: 4
}

Note: Each image counts toward your API quota.

Understanding the Response

When you generate an image, you'll receive:

{
  "success": true,
  "images": ["base64_encoded_image_or_url"],
  "generationTime": 2500
}
  • success: Whether generation succeeded
  • images: Array of generated images (base64 or URLs)
  • generationTime: How long it took (in milliseconds)

Common Use Cases

1. Marketing Materials

"professional product photo of wireless headphones, white background, studio lighting, e-commerce style"

2. Social Media Content

"vibrant instagram-style photo of avocado toast, overhead shot, natural light, rustic wooden table"

3. Concept Art

"futuristic cityscape at night, neon lights, flying cars, cyberpunk aesthetic, detailed illustration"

4. UI/UX Mockups

"modern mobile app login screen, clean design, gradient background, minimalist interface"

Rate Limits and Quotas

Be aware of API limits:

  • Free tier: 60 requests per minute
  • Paid tier: Higher limits available
  • Image generation: Each image = 1290 output tokens
  • Cost: Approximately $0.039 per image

Check your usage in the Google Cloud Console.

Error Handling

Always implement proper error handling:

try {
  const result = await generateImage({ prompt: "your prompt" });

  if (!result.success) {
    console.error("Generation failed:", result.error);
  }
} catch (error) {
  console.error("API error:", error.message);

  // Handle different error types
  if (error.message.includes("quota")) {
    console.error("Rate limit exceeded. Please try again later.");
  }
}

Best Practices

  1. Start Simple: Begin with basic prompts and add detail gradually
  2. Iterate: Generate multiple variations to find what works
  3. Be Specific: More detail usually means better results
  4. Use Examples: Reference styles, artists, or photography types
  5. Respect Limits: Monitor your API usage and implement rate limiting

Next Steps

Now that you understand the basics, continue your journey:

Troubleshooting

API Key Not Working

  • Verify the key is correct and properly set in environment variables
  • Check that billing is enabled in Google Cloud Console
  • Ensure the Gemini API is enabled for your project

Images Not Generating

  • Check your internet connection
  • Verify your API quota hasn't been exceeded
  • Try simplifying your prompt

Poor Quality Results

  • Add more descriptive details to your prompt
  • Specify the style or format you want
  • Use reference keywords like "professional photography" or "high quality"

Resources


Congratulations! You've completed the getting started guide. You're now ready to create amazing AI-generated images with Nano Banana.

Questions or feedback? Open an issue on our GitHub repository.