By Flavio
Tagged: 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, Codex, Cursor, or 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 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-runvalidates flags and prints the HTTP request offline, with credentials redacted-o jsonand--jqreturn machine-readable output without an extrajqprocess- Commands never open interactive prompts unless you pass
--interactive --usageand--schemaexpose 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 fromgit 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 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 ($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_<id> you can pass to --voice across runs:
gemini-api voices create --store=true \
--voice '{"prompted":{"input":"A warm, calm narrator with a light Italian accent"},"type":"prompted"}'
music generates full tracks with lyria-3.5. This command ran in 36.06 seconds and wrote a 2 minute 39 second stereo MP3 (44.1 kHz, 192 kbps, 3.7 MB):
gemini-api music \
"Subtle lo-fi acoustic guitar and warm Rhodes piano loop for a coding demo, 90 BPM, instrumental" \
--out ./demo-loop.mp3
video uses gemini-omni-1.2-flash and polls until the clip is ready. Add --async to return the interaction ID right away:
gemini-api video "A slow camera move over a sunlit workshop table." \
--aspect-ratio 16:9 \
--resolution 1080p \
--async
Transcribe audio and compare images #
To test transcribe, I fed the dialogue.wav file from the previous step right back in and asked for .srt subtitles:
gemini-api transcribe -i ./dialogue.wav --format srt --out ./dialogue.srt
It finished in 1.38 seconds, split the two voices cleanly, and wrote timestamps ready for a video player:
1
00:00:00,100 --> 00:00:01,800
Speaker 1: Welcome back to the build log.
2
00:00:02,300 --> 00:00:05,900
Speaker 2: Today we replaced three scripts with one CLI command.
analyze accepts images, PDFs, audio, video, CSVs, text files, and public YouTube URLs. You can pass -i multiple times to compare files in one call. Running it on the two desk images above took 5.62 seconds:
gemini-api analyze -i ./desk.jpg -i ./desk-night.jpg \
"List the exact visual differences between the first and second image in 4 short bullets."
Here is the exact response it printed:
* **Window view:** The first image shows a bright daytime sky outside, whereas the second shows a dark, starry night sky.
* **Desk lamp:** The second image adds a glowing desk lamp on the far right side of the desk, which is not present in the first image.
* **Overall lighting:** The first image is brightly lit by natural daylight, while the second is dimly lit with a warm, localized glow from the desk lamp.
* **Light patterns and shadows:** The bright sunlight patches and window-frame shadows cast across the wall, desk, and desk mat in the first image disappear in the second, replaced by soft shadows from the lamp.
Files up to 14 MB are sent inline. For larger videos or audio recordings, upload once with files upload --wait and pass the returned files/ URI to both analyze and transcribe (uploaded files expire after 48 hours):
FILE_URI=$(gemini-api files upload ./lesson-01.mp4 --wait -o json --jq '.name')
gemini-api transcribe -i "$FILE_URI" --format srt --out ./lesson-01.srt
gemini-api analyze -i "$FILE_URI" "List the main chapter timestamps as Markdown bullets."
Run Deep Research in the background #
A coding agent can launch a Gemini managed agent with --background, capture the interaction ID, and keep working while the research runs server-side:
RESEARCH_ID=$(gemini-api agent run \
"Compare open-source vector index benchmarks and cite primary papers." \
--agent deep-research-preview-04-2026 \
--background \
--jq '.id')
gemini-api agent status "$RESEARCH_ID" -o json
Use gemini-api agent cancel "$RESEARCH_ID" to stop a job. For recurring work, gemini-api triggers and gemini-api webhooks let you attach cron schedules and webhook callbacks to managed agents.
Real use cases (and how I would use it) #
Most CLI tutorials stop at “generate a hero image”, which misses where a shell-accessible multimodal tool actually saves hours. Looking at work I have been doing recently, five workflows stand out.
Dubbing multi-hour video courses without managing GPUs
I recently localized an Italian online-course and digital-products site into nine languages, including nearly 16 hours of recorded video lessons. To dub those lessons into English, I had to spin up remote GPU notebooks, install transcription and voice-cloning models, work around GPU 503 errors, and stitch audio back with ffmpeg.
With gemini-api, that pipeline collapses into two commands: replicate the speaker’s voice once with voices create, then script tts per translated segment straight to local .wav files. No Python environments or GPU timeouts to babysit.
Automated subtitle and chapter pipelines
On the same course library, every video needed subtitles in nine languages. Running files upload --wait once per video and piping the URI into transcribe --format srt (1.38 seconds on a short clip, with speaker labels built in) turns caption generation into a loop any coding agent or CI job can run.
Bulk translation with strict JSON schemas
When you translate hundreds of blog posts or structured digital-product PDFs into eight languages with free-form prompts, small formatting bugs creep in fast, like broken HTML attributes or dropped numbers in tables. Passing each file into generate --stdin --body with a strict JSON Schema forces every translated field into a predictable shape, and makes a second validation pass easy to automate.
Cross-model and visual post-deploy audits
After a big site rebuild done mostly with one coding agent, I like running a fresh read-only audit with a different model to catch dead links, missing redirects, or broken checkout flows. Having gemini-api on PATH means Claude Code or Codex can shell out to gemini-4-neon for a second opinion, or pass before/after screenshots to analyze -i before.png -i after.png to check for visual regressions without leaving the session.
Demo music and game audio inside Antigravity
Google’s Jack Wotherspoon pointed out another daily use case: letting an agent inside Antigravity call gemini-api music to drop background tracks into product demos, or gemini-api tts to generate character voices while prototyping games. Because lyria-3.5 writes a clean .mp3 directly into assets/ and prints the path, the agent can wire the file straight into a Remotion video or a browser game in the same turn.
Where it is a poor fit
gemini-api is stateless request-response HTTP only. It does not support bidirectional WebSockets, so real-time voice or live video sessions still need the Live API through the Google GenAI SDKs. It is also not a replacement for an interactive coding agent when you want multi-file editing and tool loops.
Teach your coding agent to use it #
Drop this short block into AGENTS.md, CLAUDE.md, or .cursorrules so your agent knows how to inspect flags before running commands:
## Gemini API CLI (`gemini-api`)
You have access to `gemini-api` through the shell for text, images, speech, music, video, file analysis, transcription, and managed agents.
1. Run `gemini-api --help` or `gemini-api --usage` to pick a command, and `gemini-api <command> --schema` before writing a `--body` JSON payload.
2. Preview unfamiliar calls offline with `--dry-run -o json`.
3. For a single JSON result or `--jq` filtering on streaming commands, pass `--stream=false -o json`.
4. Capture the file paths printed by media commands and the `id` values returned by `generate` or `agent run` to chain steps.
Scripts can branch on exit codes without parsing error text: 0 is success, 1 is a runtime or API error, 2 is invalid usage or conflicting flags, and 3 is an authentication failure. Pass --agent-mode to emit structured JSON errors on stderr.
Sources #
Want me to talk about your product? You can sponsor this site.