img-cli
·6 min read·Randy Lu

How to Use Nano Banana and GPT Image in Claude Code (with OpenRouter and More)

Connect Claude Code or any terminal-capable Claude workflow to Nano Banana, GPT Image, FLUX, and Seedream with img-cli. Uses OpenRouter as an example while working identically across Google, OpenAI, fal, Replicate, and 24+ providers.

  • Claude Code
  • Nano Banana
  • GPT Image
  • AI Agent
  • OpenRouter

Claude Code is great at writing code and running terminal tools, but Claude cannot emit PNG or JPEG files natively. With img-cli, three steps let Claude call Nano Banana, GPT Image, Seedream, or FLUX with your own API keys (across Google, OpenAI, OpenRouter, fal, Replicate, and 24+ providers) and save images straight into your repo:

# 1. Install and authenticate any provider (e.g. openrouter, google, openai, fal)
curl -fsSL https://img-cli.dev/install.sh | bash
img-cli provider add openrouter
img-cli provider login openrouter
# 2. Add one line to CLAUDE.md (or just mention img-cli in chat)
Use `img-cli` for image, video, and audio generation. Run `img-cli --help` first.

3. Ask Claude in plain English to generate and wire the asset:

You: "Generate a 16:9 dark-mode hero illustration with Nano Banana, save it to public/hero.png, and embed it on the home page."

Claude: Reads img-cli --help / models show → runs img-cli image into public/hero.png → reads outputs[0].file from JSON → updates your component.

Below is the full setup, why one CLI beats custom scripts or MCP servers, and how to swap providers without changing your workflow (if you also use Cursor, Codex, or chat bots like Grok Bot / Telegram, start with our overview: One CLI to Give Every AI Agent and Bot Image and Video Generation).

Why give Claude one CLI instead of raw curl or MCP servers?

Whether you call vendors directly or through an aggregator, letting an AI agent improvise image API calls breaks down for three reasons:

  1. Every vendor (and even models within one aggregator) uses a different API shape. Google Gemini returns inline base64, OpenAI image edits use multipart uploads, fal and Replicate require async polling, and even inside OpenRouter alone, Nano Banana runs on /v1/chat/completions while GPT Image 2.6 and FLUX run on /v1/images. Asking Claude to hand-roll curl calls and base64 decoders burns tokens and fails unpredictably.
  2. Unsupported flags waste money. One model takes --size 2K or 4K, another takes --aspect and -n batch counts, and reference image limits range from 1 to 16. Without client-side validation, a wrong flag triggers a failed or billed API request.
  3. Key hygiene and context overhead. Injecting API schemas or MCP tool definitions bloats every turn, and pasting API keys into chat puts secrets in conversation logs.

img-cli keeps the surface tiny and predictable for Claude:

  • One set of flags everywhere: Switching from Nano Banana to GPT Image—or from OpenRouter to Google, OpenAI, or fal—only changes -m provider:model.
  • Validated before sending: Each model declares what aspect, size, n, and ref values it accepts. Invalid commands fail locally with exit code 2 before any request is sent.
  • Keys stay out of prompts: img-cli provider login <name> saves your key in a config file only you can read—never in CLAUDE.md or chat history.
  • Structured JSON and deterministic exit codes: Passing --json -q gives Claude exact saved paths (outputs[].file) and cost info so it can wire images straight into your code.

Step 1: Install img-cli and pick a provider

1. Install the binary

macOS or Linux:

curl -fsSL https://img-cli.dev/install.sh | bash

Windows (PowerShell):

irm https://img-cli.dev/install.ps1 | iex

Or install from source with Go:

go install github.com/djyde/img-cli/cmd/img-cli@latest

2. Choose any provider behind your own API key

img-cli does not tie you to any single platform. Pick whichever service you already use:

Preference Recommended providers Notes
One key for multiple labs openrouter, fal, replicate Single balance for Nano Banana, GPT Image, FLUX, Seedream, and more
Direct vendor accounts google, openai, xai, bfl, recraft Use your own Google AI Studio, OpenAI, xAI, BFL, or Recraft keys directly
Mainland China / CNY billing vibetoken, grsai, laozhang, aihubmix, volcengine Direct access and local billing without proxy friction

Browse all 24+ official plugins on the Providers page.

3. Example setup with OpenRouter

To follow along with OpenRouter (swap openrouter for google, openai, fal, or any other provider if you prefer):

img-cli provider add openrouter
img-cli provider login openrouter

Paste your key at the hidden prompt to store it in img-cli's config file (mode 0600). In containers or CI, you can instead set OPENROUTER_API_KEY or IMG_CLI_OPENROUTER_KEY (or IMG_CLI_<NAME>_KEY for any provider).

If you mostly stick to one provider, set it as your default so you can omit the provider: prefix in -m:

img-cli provider default openrouter

Step 2: Test Nano Banana, GPT Image, and switching providers

List available image models across your installed providers:

img-cli models list --kind image

Inspect the exact flags and values a model accepts:

img-cli models show openrouter:google/gemini-nano-banana-2.1

1. Generate and edit with Nano Banana

Text-to-image at 16:9 and 2K:

img-cli image -m openrouter:google/gemini-nano-banana-2.1 \
  "a minimal ceramic teapot on an oak desk, morning window light, editorial photography" \
  --aspect 16:9 --size 2K -o out/

Multi-image editing with repeatable --ref flags (local files or URLs):

img-cli image -m openrouter:google/gemini-nano-banana-2.1 \
  "put the sofa from image 2 against the empty wall in image 1, matching light and perspective" \
  --ref room.jpg --ref sofa.jpg -o out/

2. Generate variations with GPT Image

img-cli image -m openrouter:openai/gpt-image-2.6-flare \
  "isometric technical illustration of a mechanical keyboard, dark slate background, clean lines" \
  --aspect 16:9 -n 2 -o out/

Or use openrouter:openai/gpt-5.4-image-2 for instruction-heavy chat-API edits. Files are saved cleanly as <task>-1.<ext>, <task>-2.<ext> inside out/.

3. Switch providers with zero command changes

OpenRouter is just one option. Once you add and log in to Google, OpenAI, fal, or Replicate directly, the exact same flags work unchanged:

# Direct Google Gemini API for Nano Banana
img-cli image -m google:gemini-nano-banana-2.1 "a red apple" --aspect 16:9 --size 2K -o out/

# Direct OpenAI API for GPT Image
img-cli image -m openai:gpt-image-2.6-flare "a red apple" --aspect 16:9 -n 2 -o out/

# Through fal or Grsai
img-cli image -m fal:google/nano-banana-2.1 "a red apple" --aspect 16:9 -o out/
img-cli image -m grsai:nano-banana-2.1 "a red apple" --aspect 16:9 --size 2K -o out/

Want to verify the payload before spending credits? Pass --dry-run:

img-cli image -m openrouter:openai/gpt-image-2.6-flare "a red apple" --aspect 16:9 --dry-run

Step 3: Wire img-cli into Claude via CLAUDE.md

You do not need a long prompt block in CLAUDE.md. img-cli --help, img-cli image --help, and img-cli models show already document every subcommand, --json output, model flag, and exit code—Claude learns everything it needs just by running --help.

A single line or two in your project's CLAUDE.md (or ~/.claude/CLAUDE.md) is enough—or you can simply mention img-cli directly in chat:

## Generating media

Use `img-cli` to generate images, video, speech, and music.
Run `img-cli --help` first to discover commands, flags, and exit codes, and pass `--json -q`.

For CLI discovery details and the single-file /llms.txt reference, see the AI agents guide.

Everyday prompts in Claude Code

Once configured, you can ask Claude naturally:

  1. Generate and wire an asset into your app:

    "Generate a 16:9 dark-mode hero illustration with Nano Banana, save it to public/images/, and embed it in HeroSection.tsx."

    Claude checks which Nano Banana provider you have installed (openrouter:, google:, fal:, or grsai:), verifies flags with models show, saves the image, and references outputs[0].file.

  2. Compare models side by side:

    "Run that same prompt through GPT Image (gpt-image-2.6-flare) and Seedream into out/compare/ so I can pick the best one."

  3. Composite local files with --ref:

    "Take assets/product.png and assets/desk.jpg and place the product naturally on the bottom-left corner of the desk under warm lamp light. Save to assets/mockup.png."

Step 4: Guardrails against wasted spend and duplicate charges

Every provider shares the same exit codes (see Output and exit codes):

  • Exit code 2 (invalid flag or model): Caught locally before any HTTP request is sent—zero cost. Claude reads models show and fixes the command.
  • Exit code 3 (missing or rejected key): Instructs you to run img-cli provider login <name> in your own terminal instead of asking for keys in chat.
  • Exit code 9 (network error after submit): Signals the request may have reached the provider, preventing Claude from blindly resubmitting and double-charging you.

And because the CLI contract is identical across media types, the same CLAUDE.md setup lets Claude generate videos (img-cli video with Veo, Seedance, Kling, or Hailuo), speech (img-cli speech with ElevenLabs, MiniMax, or Gemini TTS), and music (img-cli music).

FAQ

Does Claude Code support generating images natively?

No. Claude can inspect images you attach, but it cannot emit downloadable PNG or JPEG files on its own. Giving Claude a local CLI like img-cli lets it generate and save images straight into your repository just like git or npm.

Do I have to use OpenRouter to run Nano Banana or GPT Image in Claude?

No. OpenRouter is just one convenient aggregator used as an example here because a single key covers multiple labs. If you already have accounts with Google, OpenAI, xAI, BFL, fal, Replicate, VibeToken, Grsai, or LaoZhang, install that provider instead—the commands and CLAUDE.md rules are identical.

How is img-cli different from an image generation MCP server?

MCP servers inject tool schemas into every turn of your context window and often lock you into one vendor. img-cli is a single local binary with near-zero context overhead, covering 24+ image, video, speech, and music providers behind one command interface.

Are my API keys safe when Claude runs img-cli?

Yes. Keys stay in img-cli's config file or local environment variables—never in CLAUDE.md or chat—and each provider plugin declares an explicit allowlist of hostnames allowed to receive your key.

Ready to connect your agent?

Install img-cli in one command, add any official provider with your own API key, and point your agent or bot at img-cli --help.

All posts