Nano Banana image generation #
Generate, edit, and iterate on visual assets conversationally with Google’s Nano Banana models (gemini-nano-banana-2.1, gemini-3.1-flash-lite-image, gemini-3.1-flash-image, and gemini-3-pro-image) using uv run scripts/banana.py (which supports both Vertex AI / Gemini Enterprise Application Default Credentials and GEMINI_API_KEY), the gemini-api CLI (gemini-api image), or the Google Gen AI SDKs.
Fail fast with zero fallbacks on authentication or tool errors:
Never improvise workarounds if gemini-api or scripts/banana.py fails. If gemini-api is missing or fails because only Vertex AI / Gemini Enterprise credentials are present, run uv run scripts/banana.py with Application Default Credentials (GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_LOCATION="global", GOOGLE_GENAI_USE_ENTERPRISE="true", and gcloud auth application-default login). If authentication still fails, stop at once, report the exact error to the user, and ask them to configure credentials. Never invent placeholder images or fall back to unauthorized generators.
Available scripts #
- scripts/banana.py: PEP 723 standalone Python CLI (
uv run scripts/banana.py) for text-to-image generation, multimodal editing, and reference consistency with capability guards and first-class Vertex AI / Gemini Enterprise (enterprise=True,GOOGLE_CLOUD_PROJECT,GOOGLE_CLOUD_LOCATION="global", ADC) and Gemini Developer API (GEMINI_API_KEY) support. - scripts/test_banana.py: Automated CLI test suite checking flag parsing, capability guards, retired model rejection, and fail-fast authentication (
uv run scripts/test_banana.pyorpython3 scripts/test_banana.py).
Authentication and setup #
Option A: uv run scripts/banana.py (Vertex AI / Gemini Enterprise and API key) #
scripts/banana.py uses PEP 723 inline dependencies (google-genai>=3.3.0, pillow>=10.0.0, google-auth>=2.0.0), so uv run sets up an isolated environment automatically.
# 1. Authenticate with Vertex AI / Gemini Enterprise (Application Default Credentials)
gcloud auth application-default login
export GOOGLE_CLOUD_PROJECT="your-gcp-project-id"
export GOOGLE_CLOUD_LOCATION="global"
export GOOGLE_GENAI_USE_ENTERPRISE="true"
# (Or pass per command: --enterprise --project "your-gcp-project-id" --location "global")
# 2. Or authenticate with the Gemini Developer API (API key)
export GEMINI_API_KEY="your-api-key"
# 3. Verify CLI flags and capability checks offline
uv run scripts/banana.py --help
uv run scripts/test_banana.pyOption B: gemini-api CLI setup #
# 1. Verify or install gemini-api CLI on macOS and Linux
command -v gemini-api >/dev/null 2>&1 || (curl -fsSL https://raw.githubusercontent.com/google-gemini/gemini-api-cli/main/scripts/install.sh | bash)
# 2a. Configure a Gemini Developer API key
export GEMINI_API_KEY="your-api-key"
gemini-api configure --api-key "your-api-key"
# 2b. Or pass an OAuth2 bearer token for Google Cloud / ADC
gcloud auth application-default login \
--scopes="https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/generative-language"
export GEMINI_ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
export GEMINI_USER_PROJECT="your-gcp-project-id"
gemini-api whoami
gemini-api image --helpTrigger conditions #
Activate this skill whenever the user asks to:
- Generate illustrations, key art, UI assets, character sheets, sprite animation grids, or panoramic backgrounds (
1:4,4:1,1:8,8:1) up to4K. - Edit, restyle, translate, or combine existing images conversationally.
- Use “banana” as a verb (such as “banana this image” or “banana this photo into 16-bit pixel art”).
- Keep character, object, or style consistency across scenes with reference images (
-i).
Model selection and capability matrix #
| Capability / Feature | Nano Banana 2.1 (nano-banana-2.1) | Nano Banana 2 Lite (nano-banana-2-lite) | Nano Banana 2 (nano-banana-2) | Nano Banana Pro (nano-banana-pro) |
|---|---|---|---|---|
Model ID (-m) | gemini-nano-banana-2.1 | gemini-3.1-flash-lite-image | gemini-3.1-flash-image | gemini-3-pro-image |
| Primary Focus | Primary workhorse: speed, 4K, panoramas, Search grounding, multi-turn editing | Latency under 2 seconds and high throughput at low cost | Previous-generation generalist with 512px and 4K output | Studio precision, interleaved storyboards, style references |
Resolutions (-r) | 1K, 2K, 4K | 1K (1024px) only | 512px (512), 1K, 2K, 4K | 1K, 2K, 4K |
Aspect Ratios (-a) | All 14 discrete ratios (panoramic seam elimination on 1:4, 4:1, 1:8, 8:1) | All 14 discrete ratios | All 14 discrete ratios (incl. 1:4, 4:1, 1:8, 8:1) | 10 standard ratios |
| Search Grounding | Web Search + Image Search | Not supported | Web Search + Image Search | Web Search |
| Thinking Mode | minimal, medium (default), high | minimal (default), high | minimal (default), high | Enabled by default |
| Video Context | YouTube URLs and MP4 files | YouTube URLs and MP4 files | YouTube URLs and MP4 files | Not supported |
Reference Anchors (-i) | Up to 14 (up to 10 objects + 4 characters) + conversational regional edits | Up to 14 (best for single-image local edits) | Up to 14 (up to 10 objects + 4 characters) | Up to 14 (up to 6 objects + 5 characters + 3 styles) |
| Function Calling | Not supported | Supported | Not supported | Not supported |
| Reference Guide | nano-banana-2-1.md | nano-banana-2-lite.md | nano-banana-2.md | nano-banana-pro.md |
Vertex AI global endpoint, unsupported parameters, and retired models:
- Use
globalon Vertex AI / Gemini Enterprise:gemini-nano-banana-2.1runs on theglobalendpoint (us-central1returns404). - Do not pass sampling parameters to
gemini-nano-banana-2.1:seed,temperature,topP,topK, andlogprobsare unsupported and return an HTTP400API error. - Retired models: All
imagen-4.0*andimagen-3.0*models shut down on August 17, 2026, and legacygemini-2.5-flash-imageis deprecated. Migrate togemini-nano-banana-2.1,gemini-3.1-flash-lite-image, orgemini-3-pro-image.
Technical reference cards #
Consult the model cards in references/ for full resolution grids, token budgets (note 4K output uses 2,520 tokens on the Gemini Developer API and 3,780 tokens on Vertex AI / Agent Platform), and SDK examples in Python, JavaScript, Java, and Go:
- references/nano-banana-2-1.md
- references/nano-banana-2-lite.md
- references/nano-banana-2.md
- references/nano-banana-pro.md
- references/README.md
Core workflows #
1. Python CLI via uv run scripts/banana.py #
# Seamless 4:1 parallax strip with Nano Banana 2.1, medium thinking, and Image Search
uv run scripts/banana.py \
-p "A seamless 2D side-scrolling pixel-art parallax background of a synthwave city skyline" \
-f "synthwave_parallax.png" \
-m "nano-banana-2.1" \
-r "2K" \
-a "4:1" \
--thinking-level "medium" \
--image-search
# Explicit Vertex AI / Gemini Enterprise call on the global endpoint
uv run scripts/banana.py \
-p "A minimalist flat illustration of a potion bottle icon on a dark UI card" \
-f "potion_icon_lite.png" \
-m "nano-banana-2-lite" \
-a "1:1" \
--enterprise \
--project "$GOOGLE_CLOUD_PROJECT" \
--location "${GOOGLE_CLOUD_LOCATION:-global}"
# Multimodal reference edit ("banana this")
uv run scripts/banana.py \
-p "banana this character: place the character from the first image into the retro space suit from the second image on a lunar base" \
-i "assets/hero_sheet.png" \
-i "assets/spacesuit_ref.png" \
-f "astronaut_hero.png" \
-m "nano-banana-2.1" \
-r "2K"
# Validate flags and capability rules offline
uv run scripts/banana.py -p "Treasure chest icon" -f "chest.png" -m "nano-banana-2.1" -r "2K" --dry-runscripts/banana.py argument reference #
-p,--prompt: Generation or edit instructions (required).-f,--filename: Output image path (required; parent directories are created automatically).-i,--input-image: Input or reference image path (repeat up to 14 times;.png,.jpg,.jpeg,.webp,.heic,.heif).-m,--model:nano-banana-2.1(default, aliasnano-banana-2-1),nano-banana-2-lite,nano-banana-2,nano-banana-pro.-r,--resolution:512px(512,nano-banana-2only),1K(default),2K,4K.-a,--aspect-ratio:1:1(default),1:4,1:8,2:3,3:2,3:4,4:1,4:3,4:5,5:4,8:1,9:16,16:9,21:9.--thinking-level:minimal,medium(nano-banana-2.1only), orhigh.--search/--image-search: Enable Google Web Search (2.1,2,pro) or Web + Image Search (2.1,2).--api:interactions(default) ormodels(generate_contentwithGenerateContentConfig).--enterprise/--vertexai,--project,--location: Vertex AI / Gemini Enterprise ADC (GOOGLE_CLOUD_LOCATIONdefaults toglobal).--dry-run: Validate model capabilities and API configuration without calling the API.
2. CLI execution via gemini-api image #
# Single-turn generation with Nano Banana 2.1 and medium thinking
gemini-api image \
"A seamless 2D side-scrolling pixel-art parallax background of a synthwave city skyline" \
--model "gemini-nano-banana-2.1" \
--image-size "2K" \
--aspect-ratio "4:1" \
--body '{"generation_config":{"thinking_level":"medium"}}' \
--out "synthwave_parallax.png"
# Multi-turn conversational edit using --previous-interaction-id
TURN1_ID=$(gemini-api image "A cozy pixel-art developer desk with warm lamp lighting" \
--aspect-ratio "16:9" --image-size "2K" --out "studio_v1.png" --jq '.response_id')
gemini-api image "Change the window view to a rainy cyberpunk night and keep the desk untouched" \
--previous-interaction-id "$TURN1_ID" \
--out "studio_v2.png"3. Two-step character sheet to sprite grid workflow #
Splitting character design from animation grid generation keeps proportions and colors stable across frames:
- Step 1 (Reference sheet): Generate a
1:1(2K) character turnaround sheet with readable silhouette proportions (1:2to1:3head-to-body), the target camera projection (2D side-profile,top-down orthographic, or2:1 isometric), clear limb separation from the torso, and a printed 4-step color swatch bar (Shadow,Base,Light,Specular) on a flat neutral gray background. - Step 2 (
-iChroma-key sprite grid): Pass-i character_sheet.pngwith--thinking-level highto generate a uniform4x4grid (16frames) on a flat, unlit#00FF00bright green (or#FF00FFmagenta) background with zero grid lines, borders, shadows, or labels, leaving at least15%empty margin inside every cell so poses do not touch cell edges. For jump cycles, name all four phases (crouch anticipation,upward launch,rising ascent,mid-air apex).
uv run scripts/banana.py \
-p "Keep the exact character proportions and color swatches from the reference sheet. Uniform 4x4 sprite sheet grid in 2D side-profile facing right on a flat unlit #00FF00 background, no grid lines or labels, at least 15% empty #00FF00 margin inside every cell. Row 1: idle. Row 2: walk. Row 3: run. Row 4: 4-phase jump arc (crouch anticipation, launch, rising ascent, mid-air apex)." \
-i "character_sheet.png" \
-f "raw_grid_part1.png" \
-m "nano-banana-2.1" \
-r "2K" \
-a "1:1" \
--thinking-level "high"4. SDK integration patterns #
Interactions API (client.interactions.create, recommended) #
import base64
from google import genai
# Uses GEMINI_API_KEY, or pass enterprise=True, project=..., location="global"
client = genai.Client()
interaction = client.interactions.create(
model="gemini-nano-banana-2.1",
input="An infographic chart showing the timeline of space exploration milestones",
tools=[{"type": "google_search", "search_types": ["web_search", "image_search"]}],
generation_config={"thinking_level": "medium"},
response_format={"type": "image", "aspect_ratio": "16:9", "image_size": "4K"},
)
if interaction.output_image:
with open("space_milestones.png", "wb") as f:
f.write(base64.b64decode(interaction.output_image.data))Models API (client.models.generate_content) #
from google import genai
from google.genai import types
from PIL import Image
client = genai.Client()
img = Image.open("character_sheet.png")
response = client.models.generate_content(
model="gemini-nano-banana-2.1",
contents=[img, "Place this character at a cozy pixel-art developer desk with warm lighting."],
config=types.GenerateContentConfig(
response_modalities=["TEXT", "IMAGE"],
image_config=types.ImageConfig(aspect_ratio="16:9", image_size="2K"),
),
)
for part in response.candidates[0].content.parts:
if not getattr(part, "thought", False) and part.inline_data:
with open("hero_studio.png", "wb") as f:
f.write(part.inline_data.data)
breakPrompting best practices #
- Specify materials and camera: Name surface textures, lighting direction, and camera projection (
strict 2D side-profile orthographic,2:1 isometric,16-bit pixel art,cel-shaded 2D art with dark outlines). - Enforce sprite grid geometry: State exact rows/columns (
4x4 grid), unlit solid key background (#00FF00), zero borders or text labels, and15%empty cell margin. - Anchor identity with
-i: Always pass your Step 1 character sheet via-iwhen generating animation sheets or scene variations. - Target edits precisely: In multi-turn edits, name both what changes and what stays untouched (
"Change only the armor trim to gold. Keep the pose, expression, and background unchanged."). - Frame scenes positively: Describe what appears instead of negations (
"an empty, quiet cobblestone street"rather than"no cars").
