Call Gemini from any shell with the new Gemini API CLI Google released the Gemini API CLI (`gemini-api`) in beta on October 27, 2026, an open-source Go binary with no runtime dependencies that lets any shell or coding agent call Gemini models, media generators and managed agents. In testing on macOS with version 0.5.0, the author measured wall-clock times including 2.56s for structured JSON generation with `gemini-4-hydrogen`, 16.03s for a 866 KB 1K 16:9 image with `gemini-nano-banana-2.1`, 3.84s for a 296 KB multi-speaker WAV with `gemini-3.8-flash-tts` and 36.06s for a 3.7 MB MP3 with `lyria-3.5`. The tool is a stateless API client distinct from Google's interactive `@google/gemini-cli`, routing all requests through the Gemini Interactions API with conventions such as writing media files to disk, `--dry-run` request validation and `-o json` output for machine-readable results. Call Gemini from any shell with the new Gemini API CLI By Flavio https://flaviocopes.com/about/ Tagged: AI https://flaviocopes.com/tags/ai/ Call Gemini models, generate images, speech, music and video, transcribe audio and run managed agents from any shell or coding agent with gemini-api. The Gemini API CLI gemini-api lets you call Gemini models, media generators, and managed agents from any shell command. Google released it in beta on October 27, 2026 as an open-source Go binary with no runtime dependencies. It is built for coding agents that already have shell access, like Claude Code https://flaviocopes.com/claude-code-guide/ , Codex, Cursor, or Antigravity https://flaviocopes.com/antigravity/ , and it works just as well in a terminal or a CI script. Unlike @google/gemini-cli , which is Google’s interactive coding agent, gemini-api is a stateless API client that your existing agent calls when it needs a model, an asset, or a background job. I installed gemini-api v0.5.0 on macOS and tested text generation, image creation and editing, multi-speaker speech, transcription, visual diffing, and music generation against the live API. Why a CLI works well for coding agents I wrote earlier about replacing an MCP server with a CLI https://flaviocopes.com/mcp-server-to-cli/ to avoid permission prompts and extra glue. gemini-api takes the same shell-first approach, and adds a few conventions that make chaining commands predictable: - Media commands write files directly to disk and print only the output path on stdout - --dry-run validates flags and prints the HTTP request offline, with credentials redacted - -o json and --jq return machine-readable output without an extra jq process - Commands never open interactive prompts unless you pass --interactive - --usage and --schema expose the full command tree and request JSON Schema offline Everything goes through the Gemini Interactions API, so text, images, speech, music, video, file analysis, and managed agents share one binary and one auth setup. What I measured across six commands Every command below ran on gemini-api v0.5.0 from macOS using the default model for each task. Here are the wall-clock timings and outputs I got back: | Command | Default model | Wall time | Output observed | |---|---|---|---| | generate structured JSON from git log | gemini-4-hydrogen | 2.56s | Valid JSON object, 961 total tokens | | image 16:9 at 1K | gemini-nano-banana-2.1 | 16.03s | 866 KB JPEG written to disk | | image -i edit existing image | gemini-nano-banana-2.1 | 13.81s | 703 KB JPEG preserving layout | | tts --multi-speaker | gemini-3.8-flash-tts | 3.84s | 296 KB WAV 6.15s, 24 kHz mono | | transcribe --format srt | gemini-3.5-transcribe | 1.38s | 173 B .srt with speaker labels | | analyze compare 2 images | gemini-4-hydrogen | 5.62s | 4-bullet visual diff | | music | lyria-3.5 | 36.06s | 3.7 MB MP3 2m 39s, 44.1 kHz stereo | You can override any default with -m for example -m gemini-4-neon if you want Gemini 4 Neon https://flaviocopes.com/gemini-4-neon-vs-opus-5-5/ for heavier reasoning, or -m gemini-3.8-flash-lite-tts for faster dubbing . Install it and set your API key On macOS or Linux, the install script downloads the prebuilt binary and puts it in /usr/local/bin or ~/.local/bin : curl -fsSL https://raw.githubusercontent.com/google-gemini/gemini-api-cli/main/scripts/install.sh | bash If you already have Go 1.26.10 or later, go install works too: go install github.com/google-gemini/gemini-api-cli/cmd/gemini-api@latest Because the CLI is still in beta, pin a release tag in CI scripts with GEMINI VERSION : curl -fsSL https://raw.githubusercontent.com/google-gemini/gemini-api-cli/main/scripts/install.sh | GEMINI VERSION=v0.5.0 bash Create an API key in Google AI Studio. If you pay for Google AI Pro or Ultra, check whether you have unclaimed monthly API credits before you pay out of pocket. I walked through claiming your monthly Google AI Ultra API credits https://flaviocopes.com/google-ai-ultra-api-credits/ $10/month on Pro, $40 on Ultra 5x, $100 on Ultra 20x . Be careful with spend caps in Google AI Studio if you rely on those credits. Spend caps count gross usage before credits are applied, so setting a cap to $0 blocks paid requests immediately. Set the monthly cap slightly below your credit balance for example €80 against a €98.8 grant so bursts cannot spill onto your card. For CI or one-off sessions, export the key as an environment variable: export GEMINI API KEY="YOUR API KEY" On a workstation, save it in your OS keychain instead: gemini-api configure --api-key "YOUR API KEY" Verify the active credential source with whoami , then preview an HTTP request offline with --dry-run : gemini-api whoami gemini-api generate "Confirm CLI setup." --dry-run whoami prints keyring next to --api-key with a masked prefix, and --dry-run shows the exact POST body sent to v1beta/interactions without touching the network. Generate structured JSON from stdin generate streams plain text to stdout by default. Adding --stdin pipes text into the prompt, and --body lets you pass any Interactions API field, including a JSON Schema under response format . Here I piped the last eight commits from a repo into generate and asked for a typed category count, with "store": false so the interaction is not retained on the server: git log -n 8 --oneline | gemini-api generate \ "Group these commits into categories and count how many commits are in each." \ --stdin \ --stream=false \ --body '{ "response format": { "type": "text", "mime type": "application/json", "schema": { "type": "object", "properties": { "categories": { "type": "array", "items": { "type": "object", "properties": { "name": {"type": "string"}, "count": {"type": "integer"} }, "required": "name", "count" } } }, "required": "categories" } }, "store": false }' It finished in 2.56 seconds using 502 input tokens, 408 thought tokens, and 51 output tokens, returning clean JSON with no Markdown fences: {"categories": {"count":2,"name":"apps"},{"count":1,"name":"courses"},{"count":4,"name":"docs"},{"count":1,"name":"content"} } Run gemini-api generate --schema to inspect every field --body accepts. If a CLI flag and --body set the same key, the CLI exits with code 2 . Generate and edit images image writes a JPEG or PNG to disk and prints the resulting path on stdout . That makes iterative editing a two-line shell script: capture the first path, then pass it right back with -i . First, generate a 16:9 illustration at 1K --image-size accepts 512 , 1K , 2K , or 4K : DESK=$ gemini-api image \ "Minimalist developer desk with a laptop, mechanical keyboard, and warm morning coffee by a sunlit window, flat editorial illustration style, no text" \ --aspect-ratio 16:9 \ --image-size 1K \ --out ./desk.jpg That took 16.03 seconds and wrote an 866 KB JPEG: Now pass $DESK back with -i to switch the scene to night while keeping the same layout: gemini-api image \ "Change the lighting to late night with a warm desk lamp and a dark starry sky outside the window, keep the exact same desk layout" \ -i "$DESK" \ --aspect-ratio 16:9 \ --image-size 1K \ --out ./desk-night.jpg The edit took 13.81 seconds 703 KB . Every object on the desk stayed in place while the window light swapped to a starry sky and a desk lamp appeared on the right: Speech, custom voices, music and video tts writes a 24 kHz mono WAV file using gemini-3.8-flash-tts . Beyond picking a prebuilt voice with --voice , you can pass --style for acting direction, --voice-prompt to design a custom voice, or --multi-speaker for two-speaker scripts. Here is a two-speaker clip with inline style cues: gemini-api tts \ "Host warm : Welcome back to the build log. Guest excited : Today we replaced three scripts with one CLI command." \ --multi-speaker "Host=Kore,Guest=Puck" \ --out ./dialogue.wav That ran in 3.84 seconds and produced a 6.15-second WAV file 296 KB . If you need a consistent narrator or want to replicate a real speaker from reference and consent audio, gemini-api voices create creates a reusable voice