Almost every coding assistant (Claude Code, Cursor, Codex) and chat bot (Grok Bot, Telegram, Discord) can run shell commands or subprocesses—yet none of them emit images or videos natively. With img-cli, one fixed CLI gives any agent or bot access to 24+ providers for image, video, speech, and music generation using your own API keys:
# 1. Install and authenticate any provider (google, openai, xai, openrouter, fal, etc.)
curl -fsSL https://img-cli.dev/install.sh | bash
img-cli provider add openrouter
img-cli provider login openrouter
# 2. Let your agent or bot learn from --help, and run with --json -q
img-cli image -m openrouter:google/gemini-nano-banana-2.1 "product shot" -o out/ --json -q
img-cli video -m xai:grok-imagine-video-1.5 "camera orbit" --no-wait --json -q
3. One backend interface across local editors and hosted bots:
- Claude Code / Cursor / Codex: Reads
img-cli --helpandmodels show, saves assets straight intopublic/, and wires them into code.- Grok Bot / Telegram / Discord Bot: Invokes
img-cli --json -qfrom a subprocess, routes user commands to different-mmodels, and delivers async results with--no-wait+task wait.
Why one CLI beats custom glue code and per-vendor MCP servers
Whether you are wiring a local coding agent or a hosted chat bot, connecting media generation APIs breaks down in the same ways:
| Dimension | Custom scripts / per-vendor MCP | Unified img-cli |
|---|---|---|
| Switching models & vendors | Every vendor has different request payloads, polling fields, and base64 vs. URL outputs | image, video, speech, and music share identical flags everywhere; just change -m |
| Context & startup overhead | MCP servers inject dozens of tool schemas into every turn | Zero standing context cost; the agent reads img-cli --help only when needed |
| Pre-flight validation | Guessing an unsupported aspect ratio or resolution wastes a paid API call | Each model declares supports; bad flags fail locally with exit code 2 before sending |
| Retry & double-charge safety | Blindly retrying after a submit timeout can create and bill duplicate jobs | Safe reads/polls auto-retry; post-submit network failures exit with 9 to stop blind retries |
| Key hygiene | Secrets often leak into prompts, config files, or chat logs | A 0600 config file via provider login, or IMG_CLI_<NAME>_KEY env vars, plus explicit hostname allowlists |
Choosing the right integration pattern by host
Every host runs the same binary, while authentication, output paths, and async polling differ depending on where it runs.
1. Claude Code
Claude Code excels at generating landing-page visuals, product diagrams, and reference-image composites right inside your repository. You do not need a long prompt block in CLAUDE.md—two lines pointing Claude to img-cli --help are enough:
- Save keys once with
img-cli provider login, let Claude pass--json -q -o <dir>, and readoutputs[].fileto wire assets into components. - Full walkthrough (including Nano Banana vs. GPT Image,
--refedits, and switching between OpenRouter, Google, OpenAI, fal, and Grsai): 👉 How to Use Nano Banana and GPT Image in Claude Code
2. Cursor and Codex
Cursor Agent and OpenAI Codex CLI follow the same pattern via AGENTS.md (or Cursor rules):
- Add two lines from the AI agents guide telling the agent to run
img-cli --helpandimg-cli models show <provider:model> --jsonand always pass--json -q. - Because
img-clistores providers and keys once per machine, Claude Code, Codex, and Cursor all share the exact same setup immediately.
3. Grok Bot, Telegram, and Discord Bots (server-side & async)
When adding image or video generation to a Grok Bot, Telegram bot, Discord bot, or Slack app, the CLI usually runs inside Docker or a headless server. Four patterns make it rock solid:
- Headless auth via environment variables: Skip interactive
provider loginand injectIMG_CLI_<PROVIDER>_KEY(such asIMG_CLI_OPENROUTER_KEY,IMG_CLI_XAI_KEY,IMG_CLI_GOOGLE_KEY) or standard vendor env vars (OPENROUTER_API_KEY,XAI_API_KEY,OPENAI_API_KEY). - Non-blocking async tasks: Video jobs take seconds to minutes and will time out webhook handlers if run synchronously. Submit with
--no-wait --json -qto grab the taskidimmediately, then poll in a background worker withimg-cli task wait <task> --json -q -o /tmp/bot-out/(exit code8means still running). - Never double-charge on timeouts: If
img-cliexits with code9after submitting, log the task ID and report back rather than blindly resubmitting. - Command-to-model routing: Map user slash commands straight to
-m:/banana→-m google:gemini-nano-banana-2.1(oropenrouter:google/gemini-nano-banana-2.1)/gpt→-m openai:gpt-image-2.6-flare/grok→-m xai:grok-imagine-image-2.0/video→img-cli video -m xai:grok-imagine-video-1.5 ... --no-wait
4. Scripts and CI/CD pipelines
Generate docs visuals, OG assets, or audio clips in GitHub Actions with --dry-run checks, secret-injected env vars, and deterministic exit codes. See Scripts and CI.
Supported models and providers behind one CLI
Every host above unlocks the exact same catalog (full list on the Providers page):
| Media kind | Command | Example models | Official providers |
|---|---|---|---|
| Images & edits | img-cli image |
Nano Banana 2.1, GPT Image 2.6, Grok Imagine 2.0, Seedream 5.5, FLUX 3.1, Ideogram 4.6, Recraft V4 | google, openai, xai, bfl, ideogram, recraft, openrouter, fal, replicate, vibetoken, grsai, laozhang, volcengine |
| Video | img-cli video |
Veo 3.1, Seedance 2.5 / 2.0, Kling V4, Hailuo 3 / H3, Grok Imagine Video 1.5, Runway Gen-4.5 | google, xai, runway, minimax, volcengine, openrouter, fal, replicate, vibetoken |
| Speech | img-cli speech |
ElevenLabs v4, MiniMax Speech 2.8, Gemini TTS, OpenAI TTS, Cartesia Sonic, Seed-Audio | elevenlabs, minimax, google, openai, cartesia, volcengine, openrouter, vibetoken |
| Music | img-cli music |
ElevenLabs Music, MiniMax Music 3.0, Stable Audio, Lyria | elevenlabs, minimax, stability, replicate, fal, runway |
Read-only discovery commands any agent or bot can run for free:
img-cli provider list --json # installed providers and key sources
img-cli models list --kind image --json # all available image models
img-cli models show xai:grok-imagine-image-2.0 # exact allowed flags and values for one model
FAQ
Why not wrap OpenAI or Google SDKs directly inside my agent or bot?
Every vendor SDK brings its own payload format, auth setup, polling loop, and error handling. With img-cli, adding a new vendor is a single declarative .toml plugin (img-cli provider add <name>), and your agent or bot code stays unchanged.
Do I need a huge prompt in CLAUDE.md or AGENTS.md?
No. img-cli --help, img-cli <command> --help, and img-cli models show already expose everything an agent needs. Two lines telling it to check --help and pass --json -q are enough.
How do I run img-cli in Docker or on a headless Linux server?
Run img-cli provider login <name> as on a desktop; the key goes into a config file only you can read. In containers, you can instead set IMG_CLI_<PROVIDER>_KEY (such as IMG_CLI_OPENROUTER_KEY or IMG_CLI_XAI_KEY) or standard vendor environment variables (OPENROUTER_API_KEY, OPENAI_API_KEY, XAI_API_KEY). See Authentication.