Nano Banana
NanoBananaTools enables an Agent to generate images using Google's Gemini 2.5 Flash Image model (Nano Banana).
Prerequisites
You need to install the google-genai and Pillow libraries.
1uv pip install google-genai PillowSet the GOOGLE_API_KEY environment variable. You can obtain an API key from Google AI Studio.
1export GOOGLE_API_KEY=****Example
The following agent will use Nano Banana to generate an image based on a text prompt.
1from pathlib import Path23from kern.agent import Agent4from kern.tools.nano_banana import NanoBananaTools56# Example 1: Basic NanoBanana agent with default settings7agent = Agent(tools=[NanoBananaTools()], name="NanoBanana Image Generator")89# Example 2: Custom aspect ratio generator10portrait_agent = Agent(11 tools=[12 NanoBananaTools(13 aspect_ratio="2:3" # Portrait orientation14 )15 ],16 name="Portrait NanoBanana Generator",17)1819# Example 3: Widescreen generator for panoramic images20widescreen_agent = Agent(21 tools=[22 NanoBananaTools(23 aspect_ratio="16:9" # Widescreen format24 )25 ],26 name="Widescreen NanoBanana Generator",27)2829# Test basic generation30agent.print_response(31 "Generate an image of a futuristic city with flying cars",32 markdown=True,33)3435# Generate and save an image36response = widescreen_agent.run(37 "Create a panoramic nature scene with mountains and a lake at sunset",38 markdown=True,39)4041# Save the generated image if available42if response.images and response.images[0].content:43 output_path = Path("generated_image.png")44 with open(output_path, "wb") as f:45 f.write(response.images[0].content)4647 print(f"Image was successfully generated and saved to: {output_path}")Toolkit Params
| Parameter | Type | Default | Description |
|---|---|---|---|
model | str | "gemini-2.5-flash-image" | The Nano Banana model to use |
aspect_ratio | str | "1:1" | Image aspect ratio. Supported: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 |
api_key | str | None | The Google API key for authentication |
enable_create_image | bool | True | Enable the create image functionality |
Toolkit Functions
| Function | Description |
|---|---|
create_image | Generates an image based on a text prompt |
Developer Resources
- View Tools