Use when the user wants to generate or edit images with Google's Nanobanana/Gemini image models using the official Gemini API shape. Prefer this skill for text-to-image, image-to-image editing, multi-image reference workflows, attachment-based recreations, or when the user wants publication-style figures such as materials-science paper schematics. Use it when the user asks for a materials-science figure, journal-style scientific illustration, graphical abstract, mechanism diagram, or paper-ready materials figure.
Use this skill for Gemini image generation and image editing through the official generateContent flow. Follow Google's official examples and replace:
Do not use OpenAI-style /images/generations or /images/edits routes for this skill.
If the image exists only as a chat attachment and the platform does not expose a local file path, do not claim the script can upload it directly.
Use this rule:
For requests like "replace the English text in this attached image with Chinese", the fallback recreation workflow is acceptable when exact pixel-preserving edit is impossible.
Set environment variables:
export NANOBANANA_API_KEY="your-provider-key"
export NANOBANANA_BASE_URL="https://generativelanguage.googleapis.com"
export NANOBANANA_MODEL="gemini-3.1-flash-image-preview"
Optional third-party provider:
export NANOBANANA_BASE_URL="https://api.zhizengzeng.com/google"
export NANOBANANA_ALLOW_THIRD_PARTY=1
If you do not want the API key to appear in the command line, store it in a file and use:
export NANOBANANA_API_KEY_FILE="$PWD/.secrets/nanobanana_api_key"
Generate an image:
python3 scripts/generate_image.py "Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme"
Edit an image:
python3 scripts/generate_image.py "Using the provided image, change only the blue sofa to a vintage brown leather Chesterfield sofa. Keep everything else exactly the same." --input-image ./living-room.png
Recreate an attached diagram with translated labels:
python3 scripts/generate_image.py "Recreate the attached pastel technical diagram with the same layout, icons, arrows, and hand-drawn style. Replace all visible English labels with natural Simplified Chinese. Keep the composition unchanged." --aspect-ratio 16:9 --image-size 2K
Safety note:
scripts/build_materials_figure_prompt.py and --print-prompt are local-only and do not send data over the network.--allow-third-party or NANOBANANA_ALLOW_THIRD_PARTY=1.POST /v1beta/models/{model}:generateContent with X-goog-api-key.contents[].parts.
Text-only generation uses one text part. Image editing appends one or more inline image parts.generationConfig.imageConfig.
Prefer --aspect-ratio and --image-size, matching the official docs.python3 scripts/build_materials_figure_prompt.py --materials-figure ... when you want to inspect or refine the prompt before sending any API request.candidates[0].content.parts[].inlineData.
Save text parts too when returned.Required:
NANOBANANA_API_KEYNANOBANANA_BASE_URL
Must be set explicitly. Official Google endpoint: https://generativelanguage.googleapis.comOptional:
NANOBANANA_MODEL
Default: gemini-3.1-flash-image-previewNANOBANANA_TIMEOUT
Default: 120NANOBANANA_API_KEY_FILE
Path to a file containing the API key. Prefer this when you do not want the key shown in command history or command logs.NANOBANANA_ALLOW_THIRD_PARTY
Set to 1 only when you intentionally want to send API keys and user-provided files to a non-official Gemini-compatible provider.scripts/generate_image.py
Python CLI that follows the official Gemini generateContent request shape.scripts/generate_image.js
Node.js CLI with the same request format.Common options:
--input-image ./source.png--prompt-file ./background.md--aspect-ratio 16:9--image-size 2K--text-only--thinking-level high--include-thoughts--materials-figure mechanism-figure--lang zh--style-note "Nature Energy style"--print-prompt--allow-third-party--api-key-file ./.secrets/nanobanana_api_keyDefault output location:
./output/nanobanana/ relative to the current Codex working directoryOfficial Google examples:
api_key="GEMINI_API_KEY"base_url="https://generativelanguage.googleapis.com"Third-party provider replacements:
api_key="your_provider_api_key"base_url="your_google_compatible_endpoint"allow_third_party=trueOptional Zhizengzeng example:
api_key="your_zzz_api_key"base_url="https://api.zhizengzeng.com/google"allow_third_party=trueEverything else should stay aligned with the official Gemini documentation.
zh-CN prompts when image fidelity matters.If the user asks for a materials-science paper figure, journal-style scientific schematic, graphical abstract, mechanism diagram, synthesis workflow figure, microstructure-property diagram, device architecture figure, or characterization-plan figure, use the bundled materials-science templates instead of writing the prompt from scratch.
Workflow:
graphical-abstractmechanism-figuredevice-architectureprocessing-workflowenzhScientific Background slot, or use the script shortcut directly.--prompt-file or scripts/build_materials_figure_prompt.py --background-file ... instead of squeezing it into one shell argument.Python shortcut:
python3 scripts/generate_image.py "paste the scientific background here" \
--materials-figure mechanism-figure \
--lang en \
--style-note "Benchmark the figure against Nature Materials aesthetics." \
--aspect-ratio 4:3 \
--image-size 2K
JavaScript shortcut:
node scripts/generate_image.js "paste the scientific background here" \
--materials-figure graphical-abstract \
--lang zh \
--aspect-ratio 4:3 \
--image-size 2K
Prompt-only preflight:
python3 scripts/build_materials_figure_prompt.py \
--materials-figure mechanism-figure \
--lang en \
--background-file ./background.md \
--style-note "Nature Materials aesthetic with concise panel labels."
401 or 403, verify NANOBANANA_API_KEY.NANOBANANA_BASE_URL or pass --base-url.--allow-third-party or set NANOBANANA_ALLOW_THIRD_PARTY=1 only if that provider is intentional.404, verify that the request is going to /v1beta/models/{model}:generateContent.candidates[0].content.parts and check whether the request asked for image output.