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:
- A Google Account - To access Google AI Studio
- Google Gemini API Key - Free tier available
- 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
- Click on "Get API Key" button
- Select or create a Google Cloud project
- Click "Create API key"
- 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:
- Navigate to the Playground
- Enter a prompt:
"a serene mountain landscape at sunset" - Click Generate
- 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- Landscape9:16- Portrait4: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 succeededimages: 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
- Start Simple: Begin with basic prompts and add detail gradually
- Iterate: Generate multiple variations to find what works
- Be Specific: More detail usually means better results
- Use Examples: Reference styles, artists, or photography types
- Respect Limits: Monitor your API usage and implement rate limiting
Next Steps
Now that you understand the basics, continue your journey:
- API Integration Guide - Deep dive into API usage
- Advanced Prompt Engineering - Master prompt writing
- Playground - Practice generating images
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.