This page provides a ready-to-use Agent Skill: drop it into the coding agent you already use, and you can call APIYI’s Nano Banana 2 Lite (
gemini-3.1-flash-lite-image) with natural language (or explicit commands) to generate and edit images. The whole thing is just two files — copy and go.What this skill does
A single merged skill — the script auto-detects whether images are passed to decide between “text-to-image” and “image editing”:Text-to-Image
Prompt only → generate a brand-new image, supporting 14 aspect ratios, 1K canvas, ~4s per image.
Image Editing
Pass one image + instruction → local edits, style transfer, background replacement, etc.
Multi-Image Compositing
Pass multiple images + one instruction → compositing, comparison, outfit swaps, and more.
Which agents can use it
A Skill is essentially just a folder: a description written for the agent (
SKILL.md) + a script that does the work. So any coding agent that can read local files and run the command line can use it — e.g. Codex, OpenClaw, hermes-agent, Claude Code, and more.The only requirement: the machine running the agent (your computer or server) has Python 3 installed and internet access (the script connects directly to api.apiyi.com). That’s it — no specific agent required.Install in three steps
① Create the folder, paste the files
Create a skill folder and add the two files below (full contents in the next two sections):② Write your Key in the same folder
Innano-banana-lite/.env, add your APIYI API Key (created in the api.apiyi.com console):
.env automatically — no extra config or environment variables needed.
③ Hand it to the agent
- Agents with skill auto-discovery (like Claude Code): put the whole
nano-banana-lite/folder into its skills directory — user-level~/.claude/skills/or project-level.claude/skills/(shared with the repo). - Other agents: place it per their own skill/plugin conventions; or simplest of all — just tell the agent “read the SKILL.md in this folder and follow it”.
SKILL.md
Createnano-banana-lite/SKILL.md with the full contents below (the description states “what it does + when to use”, which the agent uses to auto-trigger):
scripts/nano_banana_lite.py
Createnano-banana-lite/scripts/nano_banana_lite.py using the Gemini native format (identical to this site’s text-to-image / image-editing code, verified working). Pure Python standard library — no pip install needed:
Why a single sentence generates an image
Many people wonder: I didn’t type a command, so how does saying “draw a cat” produce an image? Here’s how: when the agent starts, it first reads thedescription in each skill’s SKILL.md (a short piece of metadata stating “what this skill does and when to use it”). When your request matches that description’s scenario (e.g. “draw/generate/render an image”, “change this image to…”), the agent automatically decides to invoke this skill, reads the full SKILL.md, and runs the script — all without you memorizing any commands.
So:
- A well-written
description= more accurate auto-triggering. This skill’s description already covers phrasings like “generate/draw/edit/composite an image”. - When you don’t want the agent to guess and want 100% control, use the explicit invocation below.
How to use
Natural language (implicit trigger)
Once installed, just talk to the agent:| You say | Skill behavior |
|---|---|
| ”Use nano banana lite to make a 16:9 snow-mountain sunrise poster” | Calls the script (no -i), outputs 1 png |
| ”Make an 8:1 ultra-wide Chinese-style banner” | Calls the script --aspect 8:1, outputs 1 ultra-wide png |
| ”Give me 3 different Chinese-style landscapes” | Calls the script -n 3, outputs 3 pngs concurrently |
| ”Blur the background of photo.jpg to highlight the person” | Calls the script -i photo.jpg, outputs 1 png |
Explicit invocation (more control)
When you don’t want the agent to decide for itself, two explicit options:-
Agents with slash commands (like Claude Code):
-
Any agent / just tell it to run the script (most universal):
Where the generated images are
- When
-ois just a filename (e.g.-o dog.png), images are saved to thenano-banana-output/folder at the project root (auto-created), so you can find them right there in the project. - The “project root” = the first directory containing
.gitor.claudefound by walking up from the script — no matter which directory the agent runs in, images land inside the project, not in a temp directory where you’d lose them. - The script prints one full absolute path per image, e.g.
Image saved to /Users/you/project/nano-banana-output/dog.png. - By default only 1 image is generated;
-n 3outputs 3 at once (max 5, auto-capped above that), with-1,-2,-3suffixes added to the filename. - When you pass a path with a directory (e.g.
-o images/dog.pngor an absolute path), it saves to your given path (relative paths relative to the current working directory), not intonano-banana-output/. - Image editing works the same way: the output is a new file and never overwrites your original.
Nano Banana 2 Lite has strict content-safety controls. If the script reports
finishReason other than STOP or returns a rejection text, adjust the content per the message — don’t repeatedly retry the same violating prompt.