Image Generation (Nano Banana)
Gemini Image Generation API - Create and edit images with Imagen 3. Native multimodal image generation through UniterRouter, supports inpainting and outpainting.
Nano Banana Image Generation
Nano Banana is Google's native image generation model family built into Gemini. Generate, edit, and iterate on images through conversational prompts.
Models: gemini-2.5-flash-image (Nano Banana) for speed, gemini-3-pro-image-preview (Nano Banana Pro) for professional quality up to 4K.
Models
| Model | Description | Max Resolution | Max Input Images |
|---|---|---|---|
gemini-2.5-flash-image | Fast, high-volume tasks | 1024px | 3 |
gemini-3-pro-image-preview | Professional quality with thinking | 4K | 14 |
Text to Image
import google.generativeai as genai
genai.configure(
api_key="your_uniterouter_api_key",
transport="rest",
client_options={"api_endpoint": "api.uniterouter.ai"}
)
model = genai.GenerativeModel("gemini-2.5-flash-image")
response = model.generate_content(
"Create a picture of a futuristic city at sunset with flying cars",
generation_config={"response_modalities": ["IMAGE", "TEXT"]}
)
for part in response.parts:
if part.text:
print(part.text)
elif part.inline_data:
image = part.as_image()
image.save("generated_image.png")import { GoogleGenerativeAI } from "@google/generative-ai";
import * as fs from "fs";
const genAI = new GoogleGenerativeAI("your_uniterouter_api_key", {
baseUrl: "https://api.uniterouter.ai"
});
const model = genAI.getGenerativeModel({
model: "gemini-2.5-flash-image",
generationConfig: { responseModalities: ["IMAGE", "TEXT"] }
});
const result = await model.generateContent(
"Create a picture of a futuristic city at sunset"
);
for (const part of result.response.candidates[0].content.parts) {
if (part.text) {
console.log(part.text);
} else if (part.inlineData) {
const buffer = Buffer.from(part.inlineData.data, "base64");
fs.writeFileSync("generated_image.png", buffer);
}
}curl -X POST "https://api.uniterouter.ai/v1beta/models/gemini-2.5-flash-image:generateContent" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $UNITEROUTER_API_KEY" \
-d '{
"contents": [{"role": "user", "parts": [{"text": "Create a futuristic city"}]}],
"generationConfig": {"responseModalities": ["IMAGE", "TEXT"]}
}'Image Editing
Edit existing images with text prompts:
import base64
with open("input.jpg", "rb") as f:
image_data = base64.b64encode(f.read()).decode()
response = model.generate_content([
{"inline_data": {"mime_type": "image/jpeg", "data": image_data}},
"Change the sky to a beautiful sunset with orange and pink colors"
])Configuration
Response Modalities
generation_config = {
"response_modalities": ["IMAGE", "TEXT"] # or ["IMAGE"] for image only
}Aspect Ratio
generation_config = {
"response_modalities": ["IMAGE"],
"image_config": {
"aspect_ratio": "16:9" # 1:1, 4:3, 3:4, 16:9, 9:16
}
}Image Size (Nano Banana Pro)
generation_config = {
"response_modalities": ["IMAGE"],
"image_config": {
"image_size": "4K" # 1K, 2K, 4K
}
}Nano Banana Pro Features
Thinking Mode
Nano Banana Pro uses reasoning before generating for better composition:
model = genai.GenerativeModel("gemini-3-pro-image-preview")
response = model.generate_content(
"Create a detailed architectural rendering of a modern museum"
)Google Search Grounding
Generate images based on real-world references:
model = genai.GenerativeModel(
"gemini-3-pro-image-preview",
tools=["google_search"]
)
response = model.generate_content(
"Generate an image of the Eiffel Tower at night with current lighting"
)Multiple Reference Images
Use up to 14 reference images (5 for high fidelity):
response = model.generate_content([
image1, image2, image3,
"Combine elements from these images into a cohesive scene"
])Use Cases
| Use Case | Example Prompt |
|---|---|
| Product Design | "Design a sleek modern smartphone" |
| Art Creation | "Paint an impressionist landscape" |
| Logo Design | "Create a minimalist tech company logo" |
| Photo Editing | "Remove the background and add a beach" |
| Style Transfer | "Convert this photo to anime style" |
| Text in Images | "Create a poster with 'Welcome' text" |
Best Practices
- Be specific - Detailed prompts get better results
- Iterative editing - Use multi-turn for refinements
- Generate text first - For text in images, generate text content first
- Use references - Provide example images for style guidance
Limitations
- Supported languages: English, Chinese, Japanese, Korean, and more
- No audio/video input support
- All images include SynthID watermark
- Image count may vary from requested
Related
- Vision - Image understanding
- Generate Content - Text generation
How is this guide?
Stream Generate Content POST
Gemini Streaming API - Real-time content generation with Gemini Pro, Gemini 1.5. Reduce latency and improve UX with Server-Sent Events streaming.
Structured Output
Gemini JSON Mode API - Generate validated JSON with Gemini Pro. Schema-based structured output for reliable data extraction and type-safe AI responses.