# img-cli — A universal CLI for image, video, and audio > A plugin-based CLI for generating images, video, and audio across any AI provider, via Claude Code, Codex, Cursor, or your terminal. # img-cli docs img-cli is one command line for every image, video, and speech API. Each vendor is a provider plugin, so the commands, flags, and output stay the same whichever one you use. ## Quick start Install the CLI: ```sh curl -fsSL https://img-cli.dev/install.sh | bash ``` Add a provider and save its API key: ```sh img-cli provider add vibetoken img-cli provider login vibetoken ``` Generate: ```sh img-cli image -m vibetoken:bytedance/seedream-5.0-flash "a red apple" --aspect 1:1 -o out/ ``` Windows and other options are in [Installation](https://img-cli.dev/docs/installation/). The full walkthrough is the [Quickstart](https://img-cli.dev/docs/quickstart/). # Introduction img-cli is a command line for generating images, video, and speech through any AI vendor. The commands are designed once; each vendor plugs in as a provider file that adapts them to its API. ## What is img-cli? img-cli is a single Go binary. It gives every vendor the same three commands, `image`, `video`, and `speech`, the same flags, and the same output. A provider plugin, one TOML file, tells it how to call one vendor. Official plugins cover VibeToken, RouterBase, Grsai, and LaoZhang API, and you can write one for any other API without compiling anything. It is built to be: - **Universal:** one set of flags for every vendor. Switching vendors means changing `-m`. - **Pluggable:** vendors are data files you install, share, or write yourself. - **Safe to automate:** flags are checked against the model before anything is sent, keys live in the system keychain, and a submit is never blindly retried. - **Agent-friendly:** JSON output, stable exit codes, and a `--dry-run` that costs nothing. ## Why use img-cli? ### For people using AI assistants - Ask Claude Code, Codex, or Cursor for an image, a video, or a voiceover in plain words; the assistant runs img-cli for you. - Results are saved on your computer, and long videos keep rendering if you close the window. ### For scripts and CI - One output format and one set of exit codes for every vendor. - Keys from environment variables, isolated config with `IMG_CLI_CONFIG_DIR`, and safe retries. ### For plugin authors - Connect a new vendor by copying the request from its docs into a template. - Standard APIs need almost nothing: OpenAI Images, Videos, Speech, and Gemini are built in. ## Common workflows Generate an image from a prompt and a reference photo: ```sh img-cli image -m grsai:nano-banana-2.1 "make it watercolor" --ref photo.jpg -o out/ ``` Turn a first frame into a video, without waiting: ```sh img-cli video -m vibetoken:bytedance/seedance-2-i2v "the camera pulls back" --first-frame a.png --no-wait img-cli task wait -o out/ ``` Generate a voiceover: ```sh img-cli speech -m vibetoken:minimax/speech-2.8-hd "Welcome back." --voice English_Graceful_Lady -o hello.mp3 ``` Find a model and see what it accepts: ```sh img-cli models list --kind video img-cli models show laozhang:MiniMax-H3 ``` ## Next - [Install img-cli](https://img-cli.dev/docs/installation/) - [Run your first generation](https://img-cli.dev/docs/quickstart/) - [Understand how plugins work](https://img-cli.dev/docs/how-it-works/) # Installation img-cli is a single binary with no runtime to install. It runs on macOS, Linux, and Windows, on x64 and ARM. ## macOS and Linux ```sh curl -fsSL https://img-cli.dev/install.sh | bash ``` The script picks the build for your system, checks its SHA-256, and installs `img-cli` into `~/.local/bin`. Run it again to upgrade. | Variable | Effect | | - | - | | `IMG_CLI_VERSION` | Install a specific version, such as `v0.2.0` | | `IMG_CLI_INSTALL_DIR` | Install into another directory | | `IMG_CLI_DOWNLOAD_URL` | Download from a mirror | ```sh IMG_CLI_INSTALL_DIR="$HOME/bin" curl -fsSL https://img-cli.dev/install.sh | bash ``` ## Windows In PowerShell: ```powershell irm https://img-cli.dev/install.ps1 | iex ``` It picks the build for your CPU, checks its SHA-256, installs it to `%LOCALAPPDATA%\Programs\img-cli`, and adds that folder to your `PATH`. The same `IMG_CLI_*` variables choose the version, folder, or mirror. ## Manual download Download the archive for your system from [Releases](https://github.com/djyde/img-cli/releases) and put `img-cli` (or `img-cli.exe`) anywhere on your `PATH`. ## From source With Go installed: ```sh go install github.com/djyde/img-cli/cmd/img-cli@latest ``` ## Verify the installation ```sh img-cli version ``` If the shell cannot find `img-cli`, the install directory is not on your `PATH`; the installer prints the line to add to your shell profile. ## Uninstall Delete the binary, then, to remove providers, keys saved in files, and task records, the config directory listed in [Using providers](https://img-cli.dev/docs/providers/#where-files-live). Keys saved in the system keychain are removed with `img-cli provider logout ` before you delete the binary. ## Next - [Save a provider's key](https://img-cli.dev/docs/authentication/) - [Run your first generation](https://img-cli.dev/docs/quickstart/) # Authentication Each provider has its own API key, from that vendor's dashboard. img-cli stores it in your system keychain and sends it only to that provider. ## Save a key Install the provider first, then log in: ```sh img-cli provider add vibetoken img-cli provider login vibetoken ``` Paste the key at the hidden prompt. To pass it from a script, pipe it in: ```sh echo "$KEY" | img-cli provider login vibetoken ``` The key goes into the system keychain: macOS Keychain, Windows Credential Manager, or Secret Service on Linux. Where there is no keychain, or with `--file`, it goes into the config file, readable only by you: ```sh img-cli provider login vibetoken --file ``` ## Where keys come from For each request img-cli looks for the provider's key in this order: 1. `IMG_CLI__KEY`, such as `IMG_CLI_GRSAI_KEY`; for `my-vendor` it is `IMG_CLI_MY_VENDOR_KEY`. 2. The variable the plugin names in `auth.env`, if any. LaoZhang reads `LAOZHANG_API_KEY`. 3. The system keychain. 4. The config file. `img-cli provider list` shows where each provider's key comes from: ```text NAME TITLE BASE URL KEY grsai Grsai https://grsaiapi.com keyring laozhang LaoZhang API https://api.laozhang.ai env vibetoken * VibeToken https://vibetoken.cn keyring ``` ## In CI Set the environment variable from your CI secrets instead of logging in: ```sh export IMG_CLI_VIBETOKEN_KEY="$VIBETOKEN_API_KEY" img-cli image -m vibetoken:bytedance/seedream-5.0-flash "a fox" -o out/ ``` See [Scripts and CI](https://img-cli.dev/docs/ci/). ## With an AI assistant Log in yourself, in your own terminal. Don't paste an API key into a chat with an assistant; the setup prompt on the home page tells the assistant to ask you to run `provider login` instead. ## Remove a key ```sh img-cli provider logout vibetoken ``` `img-cli provider remove ` also deletes the key, along with the plugin. ## Errors A missing or rejected key exits with code 3: ```text error: no API key for vibetoken: run `img-cli provider login vibetoken` or set $IMG_CLI_VIBETOKEN_KEY ``` # Quickstart From install to your first image in four commands. This page uses the VibeToken provider; every other provider works the same way. ## 1. Install ```sh curl -fsSL https://img-cli.dev/install.sh | bash ``` On Windows, and for other options, see [Installation](https://img-cli.dev/docs/installation/). ## 2. Add a provider img-cli itself knows no vendor. A provider plugin tells it how to call one. Install the official VibeToken plugin: ```sh img-cli provider add vibetoken ``` Other official plugins are `routerbase`, `grsai`, and `laozhang`. You can also install a plugin from a file or URL; see [Using providers](https://img-cli.dev/docs/providers/). ## 3. Save the API key ```sh img-cli provider login vibetoken ``` Paste the key at the hidden prompt. It goes into the system keychain, one entry per provider. In CI, set `IMG_CLI_VIBETOKEN_KEY` instead; see [Authentication](https://img-cli.dev/docs/authentication/). ## 4. Generate ```sh img-cli image -m vibetoken:bytedance/seedream-5.0-flash "a red apple on a white table" --aspect 1:1 -o out/ ``` `-m` names the provider and the model, separated by a colon. img-cli submits the task, waits for it, and saves the image into `out/`: ```text submitted image task 272c496cf2cc (remote id 5d3d823c-…) 272c496cf2cc: succeeded after 13s saved out/272c496cf2cc.jpg task: 272c496cf2cc provider: vibetoken model: bytedance/seedream-5.0-flash status: succeeded cost: 0.084 CNY out/272c496cf2cc.jpg ``` ## Next - Find models and see which flags each one takes: `img-cli models list`, then `img-cli models show :`. See [Models and parameters](https://img-cli.dev/docs/models/). - Switch providers without changing anything else: `-m grsai:nano-banana-2.1`. - Make video and speech: [Video](https://img-cli.dev/docs/video/), [Speech](https://img-cli.dev/docs/speech/). - Connect a vendor that has no plugin yet: [Writing a provider](https://img-cli.dev/docs/writing-providers/). # How it works img-cli splits media generation into two parts: a command line that is the same for every vendor, and provider plugins that translate it into each vendor's API. ## The command line is fixed There are three generation commands, `image`, `video`, and `speech`, with one set of flags: `--aspect`, `--size`, `--resolution`, `--duration`, `--ref`, `--first-frame`, `--voice`, and so on. Every flag has one format. An aspect ratio is always `16:9`, a resolution is always `720p`, a duration is always whole seconds. What you get back is fixed too: a task with a status, result files, a cost, and an error message. Exit codes are the same for every vendor. So a script, or an AI agent, learns the CLI once. Moving a job from one vendor to another means changing `-m`, nothing else: ```sh img-cli image -m vibetoken:bytedance/seedream-5.0-flash "a fox" --aspect 16:9 img-cli image -m grsai:nano-banana-2.1 "a fox" --aspect 16:9 img-cli image -m laozhang:gemini-nano-banana-2.1 "a fox" --aspect 16:9 ``` ## Providers are plugins A provider is one TOML file. It says: - where the API is and how to authenticate; - how to turn img-cli's fixed input into the vendor's request body, as a template; - where the task id, status, result files, error, and cost are in the vendor's response; - which models exist, and which flags and values each model accepts. Plugins are data, not code. There is nothing to compile, and installing one is copying a file: ```sh img-cli provider add vibetoken # an official plugin img-cli provider add ./my-vendor.toml # your own img-cli provider add https://example.com/x.toml # someone else's ``` The img-cli binary contains no vendor logic. VibeToken, RouterBase, Grsai, and LaoZhang are ordinary plugin files in the [`providers/`](https://github.com/djyde/img-cli/blob/main/providers) folder of the repository, written in the same format anyone can use. ## Built-in protocols for common APIs Many vendors copy the same few public APIs. img-cli has those built in, so a plugin can point a model at one by name instead of writing a template: | Protocol | API | | - | - | | `openai-images` | OpenAI Images: generations and edits | | `openai-videos` | OpenAI Videos | | `openai-speech` | OpenAI text-to-speech | | `gemini` | Gemini `generateContent` with image output | A plugin can mix them freely. The LaoZhang plugin sends Gemini models to `gemini`, GPT Image to `openai-images`, and MiniMax H3 to its own template. ## Checked before it is sent Each model declares the flags it supports and their allowed values. img-cli checks your command against that before making any request, so a wrong value fails at once instead of after a paid round trip: ```text $ img-cli video -m laozhang:MiniMax-H3 "a cat" --resolution 1080p error: laozhang:MiniMax-H3: --resolution 1080p is not supported; use one of: 768p, 2k ``` A plugin can list these by hand, or read them from the vendor's API. The VibeToken plugin reads each model's parameter schema the first time the model is used. ## What runs where ```text you / your agent │ img-cli image -m grsai:nano-banana-2.1 "a fox" --aspect 16:9 ▼ img-cli ── parses flags, checks them against the model's supports │ ├─ grsai.toml ── renders the request body, says where the answer is │ ▼ vendor API ── submit, then poll until done │ ▼ img-cli ── records the task, downloads results, prints the same output for every vendor ``` Keys, task records, waiting, downloads, retries, and output formats belong to img-cli, so every plugin gets them for free. # Models and parameters Every model belongs to a provider and declares the flags it accepts. img-cli checks your command against that declaration before it sends anything. ## Naming a model A model is always written `provider:model`: ```sh img-cli image -m vibetoken:bytedance/seedream-5.0-flash "a fox" img-cli image -m grsai:nano-banana-2.1 "a fox" ``` The model part is the vendor's own id. After `img-cli provider default `, `-m` can name just the model: ```sh img-cli provider default vibetoken img-cli image -m bytedance/seedream-5.0-flash "a fox" ``` ## Finding models ```sh img-cli models list # every installed provider img-cli models list --provider grsai --kind image # one provider, one kind ``` Kinds are `image`, `video`, and `speech`. ## What a model accepts ```sh img-cli models show vibetoken:bytedance/seedance-2-t2v ``` ```text model: vibetoken:bytedance/seedance-2-t2v kind: video api: generations FLAG VALUES --aspect adaptive, 21:9, 16:9, 4:3, 1:1, 3:4, 9:16 --audio any --duration 4 to 15 --resolution 480p, 720p, 1080p ``` Only the listed flags work with this model. `any` means any value of the right type; a range such as `4 to 15` is inclusive. ## Checked before sending A flag the model doesn't list, or a value outside its list, fails at once with exit code 2, and nothing is sent or charged: ```text $ img-cli video -m laozhang:MiniMax-H3 "a cat" --resolution 1080p error: laozhang:MiniMax-H3: --resolution 1080p is not supported; use one of: 768p, 2k ``` Values are matched without regard to case. When a model spells a value differently, such as `720P`, you still write `720p`; img-cli sends the model's spelling. ## Where model lists come from A plugin either lists its models in the file or reads them from the vendor's API. The VibeToken plugin reads the model list and each model's parameter schema from the API, the first time they are needed. Lists and parameters read from an API are cached for a day. To pick up a new model sooner: ```sh img-cli models refresh # every provider img-cli models refresh vibetoken ``` # Tasks and results Every generation is a task. img-cli submits it, waits for it, saves its results, and keeps a local record you can come back to. ## Waiting By default `image`, `video`, and `speech` wait until the task finishes, printing progress to stderr: ```text submitted image task 272c496cf2cc (remote id 5d3d823c-…) 272c496cf2cc: succeeded after 13s ``` `--timeout` limits the wait (default 20 minutes) and `--poll-interval` sets how often to check (default: the provider's, or 3 seconds for images and 5 for video). ## Submit now, collect later `--no-wait` returns right after submitting, with the task id: ```sh img-cli video -m vibetoken:bytedance/seedance-2-t2v "a cat playing piano" --no-wait img-cli task wait 8a1c2e44b0f1 -o out/ ``` Ctrl-C, a closed terminal, or a timeout only stop the waiting. The task keeps running at the provider; `img-cli task wait ` picks it up again. ## Saving results Without `-o`, img-cli prints the result URLs. With `-o`: - `-o out/` saves every result into `out/` as `.`, or `-1.`, `-2.` for several. - `-o cat.png` saves a single result to that file. Results that come back as data instead of a URL, such as Gemini images and speech, are always saved: into `-o`, or the current directory. Result links usually expire after a few days, so save what you want to keep. ## Task records Each task is recorded locally under a short id, with its provider, model, status, results, and cost: ```sh img-cli task list # 20 most recent; --limit 0 for all img-cli task get 8a1c2e44b0f1 # one task; asks the provider if it isn't finished img-cli task get 8a1c2e44b0f1 -o out/ ``` A task remembers the host it was sent to, so changing a provider's host doesn't lose earlier tasks. ## Statuses | Status | Meaning | | - | - | | `running` | Submitted and not finished | | `succeeded` | Finished; results are in `outputs` | | `failed` | The provider rejected or failed it; the reason is in `error` | ## Costs When the provider reports a cost, it is part of the task, in the provider's currency: ```text cost: 0.084 CNY ``` `img-cli balance` shows the account balance of every provider whose plugin can read it. # Output and exit codes img-cli prints the same output, and exits with the same codes, whichever provider ran the task. Scripts and agents rely on this page. ## Text and JSON | Stream | Without `--json` | With `--json` | | - | - | - | | stdout | Results as text | Results as one JSON value | | stderr | Progress and errors | Progress and `{"error": {...}}` | Add `-q` to silence progress, and `-v` to log each HTTP request to stderr. ## A task in JSON A finished task, saved with `-o`: ```json { "id": "272c496cf2cc", "provider": "vibetoken", "model": "bytedance/seedream-5.0-flash", "kind": "image", "api": "generations", "remote_id": "5d3d823c-bc4e-4fb6-a3e0-5c754a2cc071", "status": "succeeded", "outputs": [{ "url": "https://…/0.jpg", "file": "out/272c496cf2cc.jpg" }], "cost": { "amount": 0.084, "currency": "CNY" }, "created": "2026-12-04T14:20:56Z", "updated": "2026-12-04T14:21:22Z" } ``` `outputs[].file` appears when the file was saved, `cost` when the provider reports one, and `error` when the task failed. See [Tasks and results](https://img-cli.dev/docs/tasks/#statuses) for `status`. ## Errors in JSON ```json {"error": {"exit_code": 2, "message": "laozhang:MiniMax-H3: --resolution 1080p is not supported; use one of: 768p, 2k"}} ``` When the provider returned the error, `status` holds the HTTP status. A failed task includes the whole task as `task`. ## Exit codes | Code | Meaning | What to do | | - | - | - | | 0 | Success | | | 1 | Other error | Read the message | | 2 | Invalid command, flag, value, model, or task; nothing was sent | Fix it; check `models show` | | 3 | Missing or rejected API key | `img-cli provider login ` | | 4 | The provider says it was not found | Check the model or task | | 5 | Rate limited, after img-cli's own retries | Wait, then rerun; the request was refused, not charged | | 6 | Insufficient balance | Top up; retrying won't help | | 7 | Generation failed | Change the prompt or options | | 8 | Timed out waiting | The task is still running; run `task wait ` | | 9 | Network error | Before submit: rerun. After submit: check before resubmitting | | 130 | Interrupted | The task is still running; run `task wait ` | ## Retries and double charges img-cli retries on its own where it is safe: every poll and model-list read, every rate-limited request, and submits to APIs that deduplicate them (the plugin declares `idempotency`; VibeToken and RouterBase do). `--max-retries` sets how many times (default 2). For other APIs, a submit that fails on the network may still have started a task at the provider, and submitting again would start, and bill, a second one. img-cli never retries those, and neither should your script without checking first. # Images Generate images from a prompt, edit them with reference images, and save the results. The flags are the same for every provider. ## Generate from a prompt ```sh img-cli image -m vibetoken:bytedance/seedream-5.0-flash "a red apple on a white table" --aspect 1:1 -o out/ ``` Choose the shape and size: ```sh img-cli image -m grsai:nano-banana-2.1 "a mountain lake at dawn" --aspect 16:9 --size 2K -o out/ ``` `--aspect` takes `W:H`, such as `16:9`, or `auto`. `--size` takes `1K`, `2K`, `4K`, or `WIDTHxHEIGHT`, depending on the model. ## Edit with reference images Pass one or more images with `--ref`, as a URL or a local file, and describe the change: ```sh img-cli image -m grsai:nano-banana-2.1 "make it watercolor" --ref photo.jpg -o out/ img-cli image -m vibetoken:bytedance/seedream-5.0-flash-edit \ "put the sofa from image 2 against the wall in image 1" --ref room.jpg --ref sofa.jpg -o out/ ``` Some APIs accept only public URLs; for those models a local file is rejected with a message saying so. ## Several images ```sh img-cli image -m vibetoken:bytedance/seedream-5.0-flash "a logo for a coffee shop" -n 4 -o logos/ ``` The files are saved as `-1.`, `-2.`, and so on. ## Long prompts Read the prompt from a file or another command with `-`: ```sh cat prompt.txt | img-cli image -m vibetoken:bytedance/seedream-5.0-flash - -o out/ ``` ## Flags | Flag | Format | | - | - | | `--aspect` | `W:H`, such as `16:9`, or `auto` | | `--size` | `1K`, `2K`, `4K`, or `WIDTHxHEIGHT` | | `-n`, `--n` | Number of images | | `--ref` | Reference image, URL or file; repeat for more | | `--seed` | Integer | | `--negative` | What to leave out | Each model supports some of these; `img-cli models show ` lists which. The full list of `image` flags is in the [command reference](https://img-cli.dev/docs/commands/image/). ## Tips - Run with `--dry-run` first to see the request without paying for it. - Gemini models return image data rather than a link; img-cli always saves those files, into `-o` or the current directory. # Video Generate video from a prompt, from a first and last frame, or from reference images. Video takes minutes, so this page also shows how to submit now and collect later. ## Generate from a prompt ```sh img-cli video -m vibetoken:bytedance/seedance-2-t2v "a cat playing piano" --duration 5 --aspect 16:9 -o out/ ``` `--duration` is whole seconds; `--resolution` is `480p`, `720p`, `1080p`, `2k`, or `4k`. Add `--audio` for a soundtrack on models that make one, and `--audio=false` to turn it off. ## Start from an image Animate a first frame, or set both ends: ```sh img-cli video -m laozhang:MiniMax-H3 "camera zooms out" --first-frame start.png --resolution 768p --duration 6 -o out/ img-cli video -m vibetoken:kuaishou/kling-v4-i2v "the flower blooms" --first-frame bud.png --last-frame flower.png -o out/ ``` Models that take reference images for style or characters use `--ref`, repeated for more. ## Submit now, collect later ```sh img-cli video -m vibetoken:bytedance/seedance-2-t2v "a cat playing piano" --no-wait img-cli task wait 8a1c2e44b0f1 -o out/ ``` Closing the terminal or pressing Ctrl-C doesn't stop the task; `task wait` picks it up again. See [Tasks and results](https://img-cli.dev/docs/tasks/). ## Flags | Flag | Format | | - | - | | `--aspect` | `W:H` | | `--resolution` | `480p`, `720p`, `1080p`, `2k`, `4k` | | `--duration` | Whole seconds | | `--audio` | Generate a soundtrack; `--audio=false` turns it off | | `--first-frame`, `--last-frame` | Image, URL or file | | `--ref` | Reference image; repeat for more | | `--seed`, `--negative` | As for images | Each model supports some of these, often with its own list of values; check with `img-cli models show `. The full list is in the [command reference](https://img-cli.dev/docs/commands/video/). # Speech Turn text into speech with a voice of your choice. ## Generate speech ```sh img-cli speech -m vibetoken:minimax/speech-2.8-hd "Welcome back." --voice English_Graceful_Lady -o hello.mp3 ``` Speech results are always saved: to `-o`, or the current directory. ## Pick a voice `models show` lists the voices when the plugin declares them: ```sh img-cli models show vibetoken:minimax/speech-2.8-hd ``` Pass the voice id with `--voice`. Ids with spaces need quotes: ```sh img-cli speech -m vibetoken:minimax/speech-2.8-hd "你好" --voice "Chinese (Mandarin)_News_Anchor" -o hello.mp3 ``` ## Speed and format ```sh img-cli speech -m vibetoken:minimax/speech-2.8-hd "Take a deep breath." --speed 0.9 --format wav -o calm.wav ``` ## Long text Read the text from a file with `-`: ```sh cat script.txt | img-cli speech -m vibetoken:minimax/speech-2.8-hd - --voice English_Graceful_Lady -o narration.mp3 ``` ## Flags | Flag | Format | | - | - | | `--voice` | Voice id | | `--speed` | Number, such as `1.2` | | `--format` | `mp3`, `wav`, … | The full list is in the [command reference](https://img-cli.dev/docs/commands/speech/). # AI agents Claude Code, Codex, Cursor, and other assistants that can run commands use img-cli well, because its commands, output, and exit codes are the same for every provider. An agent that learns them once can use any provider you install. ## Let the agent set it up The **Install with your assistant** button on the [home page](https://img-cli.dev/) copies a prompt for your agent. The agent installs img-cli, asks you to add a provider and log in yourself, and adds the instructions below to its own notes. ## Give your agent the CLI Paste this into your agent's instructions, such as `AGENTS.md` or `CLAUDE.md`: ```markdown ## Generating media with img-cli Use the `img-cli` CLI to generate images, video, and speech. - Always pass `--json -q`. Results are JSON on stdout; errors are JSON on stderr. - Models are `provider:model`. List them with `img-cli models list --kind --json`, and read the flags a model accepts with `img-cli models show --json`. - Use only the flags in the model's `supports`. Common ones: `--aspect 16:9`, `--size 2K`, `--resolution 720p`, `--duration 5`, `--ref ` (repeatable), `--first-frame`. - Preview a request with `--dry-run`; it sends nothing and costs nothing. - Add `-o ` to save results; the JSON then lists local paths in `outputs[].file`. - For video, pass `--no-wait`, then run `img-cli task wait --json -q -o `. Exit code 8 means the task is still running: run `task wait` again. - Exit code 2 means a flag or value was wrong and nothing was sent: fix it from `models show`. - Exit code 9 after submitting means the request may have reached the provider. Do not resubmit; tell the user, since a second submit may be charged. - If a provider is missing (`provider ... is not installed`) or has no key (exit code 3), ask the user to run `img-cli provider add ` and `img-cli provider login ` themselves. Never ask them to paste an API key into the chat. ``` The full English docs are also available as one file at . ## Discover what is available ```sh img-cli provider list --json # installed providers and where their keys come from img-cli models list --json # every model img-cli models show --json # the flags one model accepts img-cli --help # one command, as text ``` ## Output and errors The JSON shapes and exit codes the instructions above refer to are in [Output and exit codes](https://img-cli.dev/docs/output/). # Scripts and CI img-cli runs without prompts when its key comes from the environment, prints JSON with `--json`, and exits with [stable codes](https://img-cli.dev/docs/output/#exit-codes), so it fits shell scripts and CI pipelines. ## Keys from the environment Set `IMG_CLI__KEY` from your CI secrets; no login is needed: ```sh export IMG_CLI_VIBETOKEN_KEY="$VIBETOKEN_API_KEY" ``` ## Isolated config `IMG_CLI_CONFIG_DIR` keeps providers, config, task records, and caches in one directory, so a job doesn't depend on, or change, the machine's own setup: ```sh export IMG_CLI_CONFIG_DIR="$RUNNER_TEMP/img-cli" img-cli provider add vibetoken ``` ## GitHub Actions ```yaml - name: Generate cover image env: IMG_CLI_VIBETOKEN_KEY: ${{ secrets.VIBETOKEN_API_KEY }} IMG_CLI_CONFIG_DIR: ${{ runner.temp }}/img-cli run: | curl -fsSL https://img-cli.dev/install.sh | bash export PATH="$HOME/.local/bin:$PATH" img-cli provider add vibetoken img-cli image -m vibetoken:bytedance/seedream-5.0-flash "$(cat cover-prompt.txt)" --aspect 16:9 -o assets/cover.jpg --json -q ``` ## Reading the result ```sh result=$(img-cli image -m vibetoken:bytedance/seedream-5.0-flash "a fox" -o out/ --json -q) echo "$result" | jq -r '.outputs[].file' ``` ## Handling failures ```sh img-cli video -m vibetoken:bytedance/seedance-2-t2v "a cat" -o out/ --json -q --timeout 10m case $? in 0) echo "done" ;; 8) echo "still rendering; collect it later with task wait" ;; 6) echo "balance too low"; exit 1 ;; *) exit 1 ;; esac ``` Don't wrap a submit in a blind retry loop: for providers without idempotent submits, a network error after submitting may already have started a paid task. See [Retries and double charges](https://img-cli.dev/docs/output/#retries-and-double-charges). ## Test without spending `--dry-run` checks the flags and prints the request, and sends nothing. It needs no API key, and no network access for providers that list their models in the file: ```sh img-cli image -m grsai:nano-banana-2.1 "a fox" --aspect 16:9 --dry-run ``` # Using providers A provider is a plugin that connects img-cli to one vendor. This page covers installing providers, saving their keys, and choosing between them. To write your own, see [Writing a provider](https://img-cli.dev/docs/writing-providers/). ## Official providers | Name | Vendor | Notes | | - | - | - | | `vibetoken` | [VibeToken](https://vibetoken.cn) | Image, video, and speech. Models and their parameters come from the API. Prices in CNY. | | `routerbase` | [RouterBase](https://routerbase.com) | VibeToken's international service. Same models, separate accounts, prices in USD. Needs `vibetoken` installed too. | | `grsai` | [Grsai](https://grsai.ai) | Nano Banana image models. Has a mainland China host. | | `laozhang` | [LaoZhang API](https://docs.laozhang.ai) | Gemini, GPT Image, Muse video, and MiniMax H3. | They ship inside the binary but are not active until you add them. ## Install ```sh img-cli provider add vibetoken # an official provider img-cli provider add someone/img-cli-acme # img-cli.toml in a GitHub repository img-cli provider add ./acme.toml # a file on disk img-cli provider add https://example.com/acme.toml # a URL ``` `add` checks the file and copies it into the providers directory. For a file from GitHub or a URL, it first shows where your API key will be sent and asks to continue. `img-cli provider update` fetches installed providers again from where they came from. A provider can extend another, as `routerbase` extends `vibetoken`. Install the parent too; `add` reminds you. The first provider you add becomes the default. ## Save a key ```sh img-cli provider login grsai ``` Each provider has its own key. Where keys are stored, and the order img-cli looks for them in, is in [Authentication](https://img-cli.dev/docs/authentication/). ## See what is installed ```sh $ img-cli provider list NAME TITLE BASE URL KEY grsai Grsai https://grsaiapi.com keyring laozhang LaoZhang API https://api.laozhang.ai env vibetoken * VibeToken https://vibetoken.cn keyring ``` `*` marks the default provider. `KEY` says where the key comes from, or `none`. ## Choose a provider Every model reference names its provider: `-m grsai:nano-banana-2.1`. Set a default to leave it out: ```sh img-cli provider default vibetoken img-cli image -m bytedance/seedream-5.0-flash "a fox" ``` ## Regional hosts Some vendors run more than one endpoint. A plugin lists them under `[hosts]`; pick one per provider: ```sh $ img-cli provider host grsai * default https://grsaiapi.com cn https://grsai.dakka.com.cn $ img-cli provider host grsai cn ``` `img-cli provider host grsai default` goes back. Tasks remember the host they were sent to. ## Model lists Some plugins list their models in the file; others read them from the vendor's API and cache them for a day. `img-cli models refresh` picks up new models sooner; see [Models and parameters](https://img-cli.dev/docs/models/#where-model-lists-come-from). ## Try a provider without installing it `--provider-file` loads a file for one command, in place of any installed provider with the same name. Combined with `--dry-run`, it shows exactly what a plugin would send: ```sh img-cli --provider-file ./acme.toml image -m acme:pic-1 "a fox" --dry-run ``` ## Remove ```sh img-cli provider remove grsai ``` This deletes the plugin file, its saved key, and its cached model list. Task records stay. ## Where files live | What | Where | | - | - | | Installed providers | `/img-cli/providers/.toml` | | Config (default provider, hosts, file keys) | `/img-cli/config.json` | | Task records | `/img-cli/tasks/` | | Model list cache | `/img-cli//` | `` is `~/Library/Application Support` on macOS, `~/.config` on Linux, and `%AppData%` on Windows; `` is the matching cache directory. `IMG_CLI_CONFIG_DIR` moves everything into one directory. # Writing a provider A provider is one TOML file, and writing one takes no Go and no build step. You copy the request example from the vendor's API docs, replace the values with img-cli's fields, and say where the answer is in the response. This page walks through a real one, Grsai, from an empty file to a working plugin. Every key is listed in the [Provider file reference](https://img-cli.dev/docs/provider-reference/). ## Before you start From the vendor's docs, you need: - the base URL and how the API key is sent; - the request that starts a generation, with an example body; - for an asynchronous API, the request that checks a task, and its response; - the model ids and the options each one accepts. Grsai's image API, from its docs: ```text POST https://grsaiapi.com/v1/api/generate Authorization: Bearer sk-… {"model": "nano-banana-2.1", "prompt": "…", "images": ["https://…"], "aspectRatio": "1:1", "imageSize": "1K", "replyType": "async"} → {"id": "6-f671fc51-…", "status": "running"} GET https://grsaiapi.com/v1/api/result?id=6-f671fc51-… → {"id": "…", "status": "succeeded", "results": [{"url": "https://…png"}], "usage": {"credits": 1200}} status is running, succeeded, failed, or violation ``` ## 1. Name the provider Create `grsai.toml`: ```toml schema = 1 name = "grsai" title = "Grsai" base_url = "https://grsaiapi.com" currency = "credits" [auth] type = "bearer" key_url = "https://grsai.ai/zh/dashboard/api-keys" ``` `name` is what users type in `-m grsai:…` and in `provider login grsai`. `key_url` is shown when img-cli asks for the key. ## 2. Write the request An `[apis.]` table describes one request shape. Paste the example body and replace each value with a template field: ```toml [apis.generate] submit = "POST /v1/api/generate" body = ''' { "model": {{json .Model}}, "prompt": {{json .Prompt}}, {{with .Refs}}"images": [{{range .}}{{json (or .URL .Base64)}},{{end}}],{{end}} "aspectRatio": {{json .Aspect}}, "imageSize": {{json .Size}}, "replyType": "async", } ''' ``` Three rules make this work: - **Write every value with `json`.** `{{json .Prompt}}` quotes and escapes the prompt, so quotes and newlines in it cannot break the body. Numbers stay numbers. - **Unset flags disappear.** An empty value renders as `null`, and img-cli drops every `null` field before sending. If the user did not pass `--size`, there is no `imageSize` in the request. - **Trailing commas are fine.** The body is read as HuJSON, so a `range` loop can end every item with a comma, and you can add `//` comments. The templates are Go `text/template`. `{{with .Refs}}…{{end}}` writes the `images` field only when there are reference images; `{{range .}}` repeats for each one. `(or .URL .Base64)` sends a URL as is and a local file as base64, because Grsai accepts both. ## 3. Check it with --dry-run You do not need a key yet. Add a placeholder model (step 5 finishes it) and preview the request: ```toml [[models]] id = "nano-banana-2.1" kind = "image" api = "generate" ``` ```sh img-cli --provider-file grsai.toml image -m grsai:nano-banana-2.1 'a "red" fox' --aspect 16:9 --ref https://example.com/a.png --dry-run ``` ```json { "body": { "aspectRatio": "16:9", "images": ["https://example.com/a.png"], "model": "nano-banana-2.1", "prompt": "a \"red\" fox", "replyType": "async" }, "dry_run": true, "method": "POST", "url": "https://grsaiapi.com/v1/api/generate" } ``` Compare it with the vendor's example. If the template renders invalid JSON, the error shows the rendered text with line numbers. ## 4. Read the result Tell img-cli how to poll and where things are in the responses: ```toml [apis.generate] # … submit and body as above poll = "GET /v1/api/result?id={{urlquery .RawID}}" [apis.generate.result] id = "id" # in the submit response status = "status" done = ["succeeded"] failed = ["failed", "violation"] outputs = "results[].url" error = "error" cost = "usage.credits" ``` Paths use dots, and `[]` steps into each element of an array: `results[].url` collects every URL. `.ID` in a `poll` path is already path-escaped; in a query string use `{{urlquery .RawID}}`. Status values listed in neither `done` nor `failed`, such as `running`, mean the task is still going. An API without `poll` is synchronous: the submit response already holds the result. ## 5. Declare the models Each model says which flags it accepts. img-cli rejects anything else before sending a request: ```toml [[models]] id = "nano-banana-2.1" kind = "image" api = "generate" supports = { aspect = ["auto", "1:1", "16:9", "9:16", "4:3", "3:4", "21:9"], size = ["1K", "2K", "4K"], ref = 14 } ``` | Value | Means | | - | - | | `true` | any value | | `["a", "b"]` | one of these, compared case-insensitively; the listed spelling is sent | | `"4..15"` | an integer in this range | | `14` | at most this many files | Leave a flag out of `supports` and it is refused: `--n 2` now fails with `grsai:nano-banana-2.1 does not support --n (it supports --aspect, --ref, --size)`. A model with no `supports` at all sends flags unchecked, with a warning. ## 6. Try it for real ```sh img-cli provider add ./grsai.toml img-cli provider login grsai img-cli image -m grsai:nano-banana-2.1 "a red fox in the snow" --aspect 16:9 -o out/ -v ``` `-v` logs every HTTP request and response status. Check that the task finishes, the file is saved, and the cost is shown. Then try a failure, such as a prompt the vendor refuses, and check that the error message comes through. That is the whole plugin. The finished file is [`providers/grsai.toml`](https://github.com/djyde/img-cli/blob/main/providers/grsai.toml). ## Common situations ### The vendor implements a standard API Point the model at a built-in protocol and skip the template: ```toml [[models]] id = "gemini-nano-banana-2.1" kind = "image" api = "gemini" ``` Built in: `openai-images`, `openai-videos`, `openai-speech`, and `gemini`. One file can mix them with its own APIs; see [`providers/laozhang.toml`](https://github.com/djyde/img-cli/blob/main/providers/laozhang.toml). The [reference](https://img-cli.dev/docs/provider-reference/#built-in-protocols) lists the flags each protocol can send. ### Inputs go in an array with roles Some APIs want every input as an item in one list, like MiniMax H3's `content`. Write one item per input, with `with` for optional ones and `range` for repeated ones: ```toml body = ''' { "model": {{json .Model}}, "content": [ {"type": "text", "text": {{json .Prompt}}}, {{with .FirstFrame}}{"type": "image_url", "role": "first_frame", "image_url": {"url": {{json .URL}}}},{{end}} {{range .Refs}}{"type": "image_url", "role": "reference_image", "image_url": {"url": {{json .URL}}}},{{end}} ], "resolution": {{json (upper .Resolution)}}, } ''' media = "url" ``` `upper` turns img-cli's `768p` into the `768P` this API wants. `media = "url"` tells img-cli the API only fetches public URLs, so a local file is refused with a clear message instead of a vendor error. ### The models come from the vendor's API List them with `[catalog]` instead of `[[models]]`, and translate each model's parameter schema into `supports` with `[catalog.detail]`. The VibeToken plugin does both; see [`providers/vibetoken.toml`](https://github.com/djyde/img-cli/blob/main/providers/vibetoken.toml) and [Catalog](https://img-cli.dev/docs/provider-reference/#catalog). Models in `[[models]]` override the catalog, so you can fix one model by hand. ### Models of one API name a field differently When most models call it `aspect_ratio` but some call it `ratio`, give those models a `fields` entry and write the key with `default`: ```toml body = '''{ {{json (default "aspect_ratio" .Fields.aspect)}}: {{json .Aspect}} }''' [[models]] id = "seedance-2" fields = { aspect = "ratio" } # … ``` ### One vendor, several regions ```toml [hosts] cn = "https://grsai.dakka.com.cn" ``` Users switch with `img-cli provider host grsai cn`. ### Two services on the same backend Inherit everything and change what differs: ```toml schema = 1 extends = "vibetoken" name = "routerbase" base_url = "https://routerbase.com" currency = "USD" ``` ### Retries and double charges If the API deduplicates submits with a header, declare it, and img-cli sends a fresh key with each submit and retries it safely after network and server errors: ```toml idempotency = "Idempotency-Key" ``` Without it, img-cli never retries a submit, because the vendor may already have started, and charged for, the first one. ## What a provider cannot do - Send flags that are not part of img-cli's command line. Vendor-only options are left out on purpose, so the CLI stays the same everywhere. - Sign requests, as with AK/SK or JWT authentication. Only bearer tokens, a custom header, or a query parameter are supported. - Branch on complex logic. Templates have `if`, `with`, and `range`, but if a vendor needs much more, it is likely a candidate for a built-in protocol; open an issue. ## Share it The easiest way to share a provider is a GitHub repository with the file at its root, named `img-cli.toml`. Anyone can then install it by the repository's name: ```sh img-cli provider add you/img-cli-acme img-cli provider add you/img-cli-acme@v1.0.0 # a tagged version ``` A repository can hold several providers in other paths: `you/providers/acme.toml`. Tag releases so users can pin a version, and `provider update` brings them the newest one. Fill in `description`, `homepage`, and `author` at the top of the file. `add` shows them, with the hosts that will receive the user's key, before it installs. Add the GitHub topic `img-cli-provider` to the repository so others can find it. A file at any other URL works too: `img-cli provider add https://…/acme.toml`. To add it to the official list, open a pull request that adds it to [`providers/`](https://github.com/djyde/img-cli/blob/main/providers). Before sharing, check: - [ ] `--dry-run` output matches the vendor's documented request for each API; - [ ] a real generation succeeds and saves its file, for each kind of model; - [ ] a failed task shows the vendor's error message; - [ ] every model has `supports`, and unsupported flags are refused; - [ ] `key_url` points to where users create a key. # Provider file reference Every key a provider file can have. For a walkthrough, see [Writing a provider](https://img-cli.dev/docs/writing-providers/). Unknown keys are an error, so a typo fails at `provider add` instead of being ignored. ## Top level | Key | Required | Meaning | | - | - | - | | `schema` | yes | File format version. Always `1`. | | `name` | yes | Lowercase letters, digits, and dashes. Used in `-m name:model`, `provider login name`, and `$IMG_CLI__KEY`. | | `title` | | Display name. | | `description` | | One sentence on what the provider offers. Shown when installing from GitHub or a URL. | | `homepage` | | The vendor's or the file's web page. | | `author` | | Who maintains the file: a name or a GitHub user. | | `base_url` | yes, unless inherited | API origin. Paths in the file are relative to it. | | `currency` | | Unit of reported costs, such as `USD`, `CNY`, or `credits`. | | `extends` | | Name of another installed provider to inherit from. | ## `[auth]` | Key | Meaning | | - | - | | `type` | `bearer` (default) sends `Authorization: Bearer `; `header` sends the key in the header named by `header`; `query` adds it as the query parameter named by `query`. | | `header` | Header name, for `type = "header"`, such as `x-goog-api-key`. | | `query` | Parameter name, for `type = "query"`. | | `env` | An extra environment variable to read the key from, such as `LAOZHANG_API_KEY`. `$IMG_CLI__KEY` is always read first. | | `key_url` | Where users create a key; shown by `provider login`. | ## `[hosts]` Alternative origins by name, picked with `img-cli provider host `: ```toml [hosts] cn = "https://grsai.dakka.com.cn" ``` ## `[apis.]` One request shape. Models refer to it by name with `api = ""`. | Key | Meaning | | - | - | | `submit` | `"METHOD /path"`, a template. Starts the generation. | | `body` | JSON body template. Omit for a request without a body. | | `poll` | `"METHOD /path"`, a template. Checks a task. Omit for a synchronous API. | | `poll_every` | Time between polls, such as `"10s"`. Default 3s for images and speech, 5s for video. | | `media` | `"url"` when the API accepts only public URLs for input files; local files are then refused. | | `idempotency` | Header name, when the API deduplicates submits by a key in it. img-cli then sends a new UUID with each submit and retries the submit after network and server errors. Without it, submits are never retried. | ### `[apis..result]` Where values are in the responses. Paths are dot-separated keys; `[]` steps into each array element, as in `data[].url` or `candidates[].content.parts[]`. | Key | Read from | Meaning | | - | - | - | | `id` | submit response | Task id. Required when there is a `poll`. | | `status` | submit and poll responses | Status value. | | `done` | | Status values that mean success. | | `failed` | | Status values that mean failure. Any other value means still running. | | `outputs` | | Path to result URLs. | | `outputs_base64` | | Path to result data, as base64 or `data:` URIs. | | `error` | | Path to the error message. | | `cost` | | Path to the cost, a number in `currency`. | A synchronous API without `status` succeeds when it has outputs. A success with no outputs is reported as a failure, with `error` or the response body as the message. ## Templates Templates are Go [`text/template`](https://pkg.go.dev/text/template). ### Body rules 1. Write every value with `json`. It escapes strings and keeps numbers and booleans typed. Nil, empty strings, and empty lists render as `null`. 2. The rendered text is parsed as [HuJSON](https://github.com/tailscale/hujson): trailing commas and `//` and `/* */` comments are allowed. 3. Every field whose value is `null`, and every `null` array element, is removed before sending. ### Functions | Function | Does | | - | - | | `json` | Encode a value as JSON, empty as `null`. | | `upper`, `lower` | Change case. | | `default` | `{{default "x" .V}}` is `.V`, or `"x"` when `.V` is empty. | | `urlquery` | Escape for a query string. | Go's built-ins also work: `if`, `with`, `range`, `or`, `and`, `eq`, `print`, `len`, `index`. ### Fields | Field | Type | From | | - | - | - | | `.Kind` | string | `image`, `video`, or `speech` | | `.Model` | string | model id, without the provider | | `.Prompt` | string | prompt; the text to speak, for speech | | `.Negative` | string | `--negative` | | `.Aspect` | string | `--aspect`, such as `16:9` | | `.Size` | string | `--size` | | `.Resolution` | string | `--resolution`, lowercase, such as `720p` | | `.Duration`, `.N`, `.Seed` | integer or nil | `--duration`, `--n`, `--seed` | | `.Audio` | boolean or nil | `--audio` | | `.Voice`, `.Format` | string | `--voice`, `--format` | | `.Speed` | number or nil | `--speed` | | `.Refs` | list of files | `--ref` | | `.FirstFrame`, `.LastFrame` | file or nil | `--first-frame`, `--last-frame` | | `.Fields` | map | the model's `fields` | | `.ID` | string | task id, path-escaped; in `poll` only | | `.RawID` | string | task id as returned; in `poll` only | When a model lists allowed values in `supports`, the field holds the listed spelling: a user's `720p` becomes `720P` if that is what the model lists. Each file has: | Field | Meaning | | - | - | | `.URL` | the remote URL; empty for a local file | | `.Base64` | the file data in base64 | | `.DataURI` | `data:;base64,` | | `.MIME` | media type | Local files are read only when a template uses `.Base64` or `.DataURI`. Using them on a URL is an error, so write `(or .URL .Base64)` to accept both. ## `[[models]]` | Key | Meaning | | - | - | | `id` | Model id, as the vendor spells it. | | `kind` | `image`, `video`, or `speech`. | | `api` | An `[apis]` name or a built-in protocol. | | `supports` | The flags the model accepts; see below. | | `fields` | Per-model values for templates, read as `.Fields.`. Typically vendor field names that differ between models. | ### `supports` Keys are flag names with underscores: `aspect`, `size`, `resolution`, `duration`, `n`, `seed`, `negative`, `audio`, `voice`, `speed`, `format`, `ref`, `first_frame`, `last_frame`. | Value | Means | | - | - | | `true` | any value | | `false` or absent | not supported | | list | allowed values, compared case-insensitively | | `"min..max"` | an integer range | | number | for file flags: the most files | A flag the model does not support is refused before any request. A model without `supports` sends whatever flags its API can carry, with a warning. ## Built-in protocols Use these as `api` values. The flags each one can send are fixed; any other flag is refused. | Protocol | Requests | Flags | | - | - | - | | `openai-images` | `POST /v1/images/generations` (JSON); with `--ref`, `POST /v1/images/edits` (multipart, field `image[]`). Results from `data[].url` or `data[].b64_json`. | `--size`, `--n`, `--ref` | | `openai-videos` | `POST /v1/videos` (multipart with `input_reference` when there is a first frame); polls `GET /v1/videos/{id}`; downloads `video_url` or `GET /v1/videos/{id}/content`. | `--duration` (as `seconds`), `--resolution` as `WIDTHxHEIGHT` (as `size`), `--first-frame` | | `openai-speech` | `POST /v1/audio/speech`; the response body is the audio. | `--voice`, `--speed`, `--format` (as `response_format`) | | `gemini` | `POST /v1beta/models/{model}:generateContent` with `responseModalities: ["IMAGE"]`; local files as `inlineData`, URLs as `fileData`; thought images are skipped. | `--aspect`, `--size`, `--ref` | Authentication still comes from the provider's `[auth]`, so `gemini` works with Google's `x-goog-api-key` and with gateways that use bearer tokens. ## Catalog `[catalog]` reads the model list from the vendor. Models in `[[models]]` take precedence over models with the same id. | Key | Meaning | | - | - | | `get` | Path of the list request. | | `items` | Path to the array of models; empty when the response is the array. | | `id` | Path to the id within an item. Default `id`. | | `kind` | Path to the vendor's modality within an item. | | `kinds` | Map from the vendor's modality to img-cli's kind, such as `{ audio = "speech" }`. | | `apis` | Map from kind to the API to use. Models of kinds not in this map are skipped. | | `cache` | How long to keep the list, such as `"6h"`. Default 24h. | ### `[catalog.detail]` Reads one model's parameters when the model is used or shown, and turns them into `supports` and `fields`. | Key | Meaning | | - | - | | `get` | Path template; `.ID` is the escaped model id. | | `template` | Template over the detail response that renders `{"supports": {...}, "fields": {...}}`. Unlike body templates, missing keys are fine and render as empty. | | `cache` | Default 24h. | Example, from the VibeToken plugin: ```toml [catalog.detail] get = "/api/v1/models/{{.ID}}" template = ''' {{$f := .parameter_schema.fields}} { "supports": { {{with or $f.aspect_ratio $f.ratio}}"aspect": {{json .rules.values}},{{end}} {{with $f.duration}}{{with .rules}}"duration": "{{.min}}..{{.max}}",{{end}}{{end}} }, "fields": { {{if $f.ratio}}"aspect": "ratio",{{end}} }, } ''' ``` If the detail request fails, img-cli warns and sends flags unchecked. ## `[balance]` | Key | Meaning | | - | - | | `get` | Path of the balance request. | | `amount` | Path to the amount. | | `currency` | Path to the currency; falls back to the top-level `currency`. | ## `extends` A provider with `extends = ""` starts from the parent and overrides: - `title`, `base_url`, `currency`, and each `[auth]` key that it sets; - `[hosts]`, `[catalog]`, and `[balance]` as whole tables; - `[apis.]` and `[[models]]` entries with the same name or id; others are added. The parent must be installed. # Commands Every img-cli command, grouped by what it does. `img-cli --help` shows the same with examples. ## Command structure ```sh img-cli [subcommand] [arguments] [flags] ``` Global flags can go before or after the command: ```sh img-cli --json image -m grsai:nano-banana-2.1 "a fox" img-cli image -m grsai:nano-banana-2.1 "a fox" --json ``` ## Command families ### Generate - [image](https://img-cli.dev/docs/commands/image/): generate images - [video](https://img-cli.dev/docs/commands/video/): generate a video - [speech](https://img-cli.dev/docs/commands/speech/): turn text into speech ### Manage - [provider](https://img-cli.dev/docs/commands/provider/): install providers and save their API keys - [models](https://img-cli.dev/docs/commands/models/): list models and what they support - [task](https://img-cli.dev/docs/commands/task/): check, wait for, and list tasks - [balance](https://img-cli.dev/docs/commands/balance/): show account balances ### Other - `version`: print the version - `completion `: print a shell completion script for bash, zsh, fish, or PowerShell ## Global flags | Flag | Meaning | | - | - | | `--json` | Print results as JSON, and errors as JSON on stderr | | `-q`, `--quiet` | Hide progress messages | | `-v`, `--verbose` | Log each HTTP request to stderr | | `--dry-run` | Print the request instead of sending it | | `--provider-file ` | Use this provider file instead of the installed one with the same name; repeatable | | `--http-timeout ` | Timeout for one HTTP request (default 10m) | | `--max-retries ` | Retries for rate limits and for requests that are safe to repeat (default 2) | ## Environment variables | Variable | Meaning | | - | - | | `IMG_CLI__KEY` | API key for provider ``; dashes become underscores | | `IMG_CLI_CONFIG_DIR` | Keep config, providers, tasks, and cache in this directory | | `IMG_CLI_VERSION`, `IMG_CLI_INSTALL_DIR`, `IMG_CLI_DOWNLOAD_URL` | Installer options; see [Installation](https://img-cli.dev/docs/installation/) | ## Exit codes 0 ok, 1 error, 2 usage, 3 auth, 4 not found, 5 rate limited, 6 insufficient credits, 7 generation failed, 8 wait timed out, 9 network, 130 interrupted. See [Output and exit codes](https://img-cli.dev/docs/output/#exit-codes). # image Generate images from a prompt, optionally with reference images. ## Quick start ```sh img-cli image -m vibetoken:bytedance/seedream-5.0-flash "a red apple" --aspect 16:9 -o out/ img-cli image -m grsai:nano-banana-2.1 "make it watercolor" --ref photo.jpg --size 2K ``` ## Usage ```sh img-cli image [prompt...] -m [flags] ``` Pass the prompt as arguments, with `--prompt`, or as `-` to read stdin. ## Flags | Flag | Meaning | | - | - | | `-m`, `--model` | `provider:model`, or a model of the default provider (required) | | `-p`, `--prompt` | Prompt, or `-` for stdin | | `--aspect` | Aspect ratio `W:H`, such as `16:9`, or `auto` | | `--size` | `1K`, `2K`, `4K`, or `WIDTHxHEIGHT` | | `-n`, `--n` | Number of images | | `--ref` | Reference image: URL or file; repeatable | | `--seed` | Random seed | | `--negative` | What to leave out | | `-o`, `--out` | Save results into this directory, or to this file when there is one result | | `--no-wait` | Return right after submitting | | `--timeout` | How long to wait for the result (default 20m) | | `--poll-interval` | Time between status checks (default: the provider's, or 3s) | Plus the [global flags](https://img-cli.dev/docs/commands/#global-flags). A model accepts only some of these; `img-cli models show ` lists which. ## See also - [Images guide](https://img-cli.dev/docs/images/) - [Tasks and results](https://img-cli.dev/docs/tasks/) # video Generate a video from a prompt, frames, or reference images. ## Quick start ```sh img-cli video -m vibetoken:bytedance/seedance-2-t2v "a cat playing piano" --duration 5 --aspect 16:9 img-cli video -m laozhang:MiniMax-H3 "camera zooms out" --first-frame https://example.com/a.png --resolution 768p --duration 6 ``` ## Usage ```sh img-cli video [prompt...] -m [flags] ``` Pass the prompt as arguments, with `--prompt`, or as `-` to read stdin. ## Flags | Flag | Meaning | | - | - | | `-m`, `--model` | `provider:model`, or a model of the default provider (required) | | `-p`, `--prompt` | Prompt, or `-` for stdin | | `--aspect` | Aspect ratio `W:H`, such as `16:9` | | `--resolution` | `480p`, `720p`, `1080p`, `2k`, `4k` | | `--duration` | Length in whole seconds | | `--audio` | Generate a soundtrack; `--audio=false` to turn it off | | `--first-frame` | First frame image: URL or file | | `--last-frame` | Last frame image: URL or file | | `--ref` | Reference image: URL or file; repeatable | | `--seed` | Random seed | | `--negative` | What to leave out | | `-o`, `--out` | Save results into this directory, or to this file when there is one result | | `--no-wait` | Return right after submitting | | `--timeout` | How long to wait for the result (default 20m) | | `--poll-interval` | Time between status checks (default: the provider's, or 5s) | Plus the [global flags](https://img-cli.dev/docs/commands/#global-flags). A model accepts only some of these; `img-cli models show ` lists which. ## See also - [Video guide](https://img-cli.dev/docs/video/) - [task wait](https://img-cli.dev/docs/commands/task/#task-wait) # speech Turn text into speech. ## Quick start ```sh img-cli speech -m vibetoken:minimax/speech-2.8-hd "Welcome back." --voice English_Graceful_Lady -o hello.mp3 ``` ## Usage ```sh img-cli speech [text...] -m [flags] ``` Pass the text as arguments, with `--prompt`, or as `-` to read stdin. ## Flags | Flag | Meaning | | - | - | | `-m`, `--model` | `provider:model`, or a model of the default provider (required) | | `-p`, `--prompt` | Text, or `-` for stdin | | `--voice` | Voice id | | `--speed` | Speaking speed, such as `1.2` | | `--format` | Audio format, such as `mp3` or `wav` | | `-o`, `--out` | Save the result to this file or directory (default: the current directory) | | `--timeout` | How long to wait for the result (default 20m) | | `--poll-interval` | Time between status checks, for providers that run speech as a task | Plus the [global flags](https://img-cli.dev/docs/commands/#global-flags). `img-cli models show ` lists a model's voices and formats. ## See also - [Speech guide](https://img-cli.dev/docs/speech/) # provider Install provider plugins, save their API keys, and choose between them. ## Quick start ```sh img-cli provider add vibetoken img-cli provider login vibetoken img-cli provider list ``` ## Subcommands - [add](#provider-add): install a provider - [update](#provider-update): fetch installed providers again - [list](#provider-list): list installed providers - [login](#provider-login): save a provider's API key - [logout](#provider-logout): delete a provider's saved key - [default](#provider-default): use a provider when `-m` names only a model - [host](#provider-host): show or pick a regional host - [remove](#provider-remove): uninstall a provider ## provider add ```sh img-cli provider add [--yes] ``` | Argument | Installs | | - | - | | `vibetoken` | An official provider: `vibetoken`, `routerbase`, `grsai`, or `laozhang`. | | `owner/repo` | `img-cli.toml` from that GitHub repository's default branch. | | `owner/repo/path/acme.toml@v1.2.0` | Another file in the repository, at a tag, branch, or commit. | | `./acme.toml` | A file on disk. | | `https://example.com/acme.toml` | A file at a URL. | Before installing from GitHub or a URL, `add` shows the file's title, description, and author, and every host your API key will be sent to, then asks to continue. Pass `--yes` to skip the question in scripts; without a terminal, `add` refuses unless you do. img-cli sends the key only to those hosts, even when a template builds a URL elsewhere. A file from GitHub is pinned to the commit it was downloaded at. `add` records where each file came from, so [`provider update`](#provider-update) can fetch it again. Adding a file whose `name` is already installed replaces it. A provider that extends another needs the parent installed too. ```sh img-cli provider add someone/img-cli-acme img-cli provider add ./my-provider.toml --yes ``` ## provider update ```sh img-cli provider update [name...] [--yes] ``` Fetches each installed provider again from where it was added: the official file in this build, the GitHub repository at its tag or default branch, the URL, or the local file. Without names, every provider is updated. If the new file sends the key to different hosts, `update` shows them and asks again; `--yes` accepts. ```sh img-cli provider update img-cli provider update acme ``` ## provider list ```sh img-cli provider list ``` Shows each installed provider, its base URL, and where its key comes from (`env`, `keyring`, `file`, or `none`). `*` marks the default. ## provider login ```sh img-cli provider login [--file] ``` Reads the key from a hidden prompt, or from stdin when piped, and saves it in the system keychain. `--file` saves it in the config file instead. See [Authentication](https://img-cli.dev/docs/authentication/). ## provider logout ```sh img-cli provider logout ``` Deletes the saved key from the keychain and the config file. ## provider default ```sh img-cli provider default ``` After this, `-m` can name a model of this provider without the `provider:` prefix. The first provider you add becomes the default. ## provider host ```sh img-cli provider host # list hosts; * marks the current one img-cli provider host # pick one img-cli provider host default # go back ``` For vendors with regional endpoints listed in the plugin's `[hosts]`. ## provider remove ```sh img-cli provider remove ``` Deletes the plugin file, its saved key, and its cached model list. Task records stay. # models List the models of installed providers and the flags each one accepts. ## Quick start ```sh img-cli models list --kind video img-cli models show vibetoken:bytedance/seedance-2-t2v ``` ## Subcommands - [list](#models-list): list models - [show](#models-show): show the flags a model accepts - [refresh](#models-refresh): forget cached model lists ## models list ```sh img-cli models list [--provider ] [--kind image|video|speech] ``` | Flag | Meaning | | - | - | | `--provider` | Only this provider | | `--kind` | Only this kind: `image`, `video`, or `speech` | ## models show ```sh img-cli models show ``` Prints the model's kind, the API it uses, and each flag it supports with its allowed values. See [Models and parameters](https://img-cli.dev/docs/models/#what-a-model-accepts). ## models refresh ```sh img-cli models refresh [provider] ``` Model lists and parameters read from a vendor's API are cached for a day. This clears the cache for one provider, or all of them. # task Check, wait for, and list generation tasks recorded on this machine. ## Quick start ```sh img-cli task list img-cli task wait 8a1c2e44b0f1 -o out/ ``` ## Subcommands - [get](#task-get): show a task - [wait](#task-wait): wait for a task to finish - [list](#task-list): list recent tasks ## task get ```sh img-cli task get [-o ] ``` Shows a task. If it isn't finished, img-cli asks the provider once for its current status. `-o` saves its results. ## task wait ```sh img-cli task wait [-o ] [--timeout ] [--poll-interval ] ``` Waits until the task finishes, then prints or saves its results. Use it after `--no-wait`, a timeout (exit code 8), or Ctrl-C. | Flag | Meaning | | - | - | | `-o`, `--out` | Save results into this directory, or to this file when there is one result | | `--timeout` | How long to wait (default 20m) | | `--poll-interval` | Time between status checks | ## task list ```sh img-cli task list [--limit ] ``` Recent tasks, newest first. `--limit` sets how many (default 20; `0` for all). ## See also - [Tasks and results](https://img-cli.dev/docs/tasks/) # balance Show the account balance at each provider. ## Quick start ```sh img-cli balance img-cli balance --provider vibetoken ``` ## Usage ```sh img-cli balance [--provider ] ``` | Flag | Meaning | | - | - | | `--provider` | Only this provider | Lists every installed provider whose plugin declares a `[balance]` endpoint, in that provider's currency. Providers without one are skipped. # FAQ Short answers to common questions. ## What is a provider? A plugin that connects img-cli to one vendor's API. It is a single TOML file that says where the API is, how to build the request, and where the answer is. See [How it works](https://img-cli.dev/docs/how-it-works/). ## Which services are supported? The official providers are VibeToken, RouterBase, Grsai, and LaoZhang API. Any other API can be added with a provider file; see [Writing a provider](https://img-cli.dev/docs/writing-providers/). ## Do I need to know how to code? No. Install img-cli with the setup prompt for your AI assistant, then ask the assistant for what you want. Writing a new provider needs only an API's docs and a text editor, no programming. ## Is img-cli free? Yes, img-cli is free, and its source is on [GitHub](https://github.com/djyde/img-cli). You pay each vendor for what you generate, at their prices, from your own account. ## Where are my API keys stored? In the system keychain (macOS Keychain, Windows Credential Manager, Secret Service on Linux), one entry per provider, or in an environment variable you set. They are sent only to that provider. See [Authentication](https://img-cli.dev/docs/authentication/). ## Does it work with Claude Code, Codex, or Cursor? Yes, and with any assistant that can run terminal commands. See [AI agents](https://img-cli.dev/docs/ai-agents/). ## How do I switch to another vendor? Install its provider, log in, and change `-m`. Your flags and scripts stay the same, as long as the new model supports the flags you use; `img-cli models show` tells you. ## Will a failed command still charge me? A command rejected by img-cli's checks (exit code 2) sends nothing. A task the vendor runs and fails may be billed by that vendor's rules. img-cli never resubmits a request that could start a second paid task; see [Retries and double charges](https://img-cli.dev/docs/output/#retries-and-double-charges). ## Can I use VibeToken and RouterBase together? Yes. Each provider has its own key, so you can install both and pick one per command with `-m vibetoken:…` or `-m routerbase:…`. ## Does it support 3D or music? Not yet. img-cli generates images, video, and speech. # Troubleshooting Common errors and how to fix them. Add `-v` to any command to log each HTTP request, which shows what was sent and what came back. ## `command not found: img-cli` The install directory isn't on your `PATH`. The macOS and Linux installer uses `~/.local/bin`; add it to your shell profile: ```sh echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc ``` Then open a new terminal. On Windows, open a new PowerShell window after installing. ## `provider "x" is not installed` ```text error: provider "grsai" is not installed; install it with: img-cli provider add grsai ``` Run the command it suggests. A provider that extends another, such as `routerbase`, needs its parent installed too. ## `no API key for x` (exit code 3) No key was found. Run `img-cli provider login `, or set `IMG_CLI__KEY`. If you already logged in, the key may have been rejected by the vendor; log in again with a new key from its dashboard. In a sandbox that can't reach the system keychain, such as some AI assistants, use the environment variable or `provider login --file`. ## `--x is not supported` (exit code 2) ```text error: laozhang:MiniMax-H3: --resolution 1080p is not supported; use one of: 768p, 2k ``` The model doesn't take that flag or value. Pick one from the message, or see everything the model takes with `img-cli models show `. Nothing was sent. ## `x has no model "y"` Check the spelling with `img-cli models list --provider `. If the vendor added the model recently, run `img-cli models refresh `. ## The wait timed out (exit code 8) The task is still running at the provider. Collect it with: ```sh img-cli task wait -o out/ ``` Raise `--timeout` for long videos. ## Rate limited (exit code 5) or insufficient balance (exit code 6) img-cli has already retried rate limits. Wait a minute and run again. For balance, top up at the vendor; `img-cli balance` shows what's left. ## Network error after submitting (exit code 9) The task may have started at the provider. Check the vendor's dashboard, or `img-cli task list`, before you run the command again, so you don't pay twice. ## A local file is rejected Some APIs accept only public `https://` URLs for input images. Upload the file somewhere public and pass the URL instead. ## Still stuck Open an issue at [GitHub](https://github.com/djyde/img-cli/issues) with the command, the output of the same command with `-v`, and `img-cli version`. Remove your API key from anything you paste.