Gemini API CLI (gemini-api)
Gemini models and managed agents for the agent you already use.
Give Codex, Claude Code, Antigravity, OpenClaw, Hermes, or any other agent with shell access the ability to use the Gemini API. Configure an API key, put gemini-api on PATH, and let your agent choose a model, generate an asset, analyze a file, or launch a managed agent to handle a task.
Your agent plans the work. Gemini provides models and managed agents. This stateless CLI connects them through standard shell commands:
gemini-api image "A friendly robot mascot for a developer tool" --out ./assets/
A prompt goes in. An image lands in your project. Your agent gets the file path and keeps building. The same binary can return an analysis, a voiceover, a transcript, or the interaction ID of a background managed-agent run.
Installation · Quick start · Command overview · Agent discovery · Workflows · Self-hosted environments · Contributing · Gemini API docs
Bugs and feedback: Open a GitHub Issue. We do not accept pull requests — see CONTRIBUTING.md.
Why this CLI
A coding agent building an app may need a hero image, a voiceover, a second opinion on a design, or an answer inside a PDF. An assistant may need to turn a recording into captions or delegate multi-step research. Give that agent gemini-api and an API key, and it can call those capabilities directly when the task requires them.
- One binary for models, media, and managed agents: Access text and reasoning models, multimodal file analysis, image/audio/music/video generation, and managed agents from the command line.
- Delegate long-running work: Start a Gemini managed agent in the background, keep the returned interaction ID, and retrieve the result when needed.
- Self-describing interface: Commands, flags, request schemas (
--schema), and machine-readable usage (--usage) are built into the binary so an agent can inspect what it needs on the fly.
- Safe dry-run validation:
--dry-run validates inputs and prints the resolved HTTP request with credentials redacted—without making a network call or reading the OS keychain.
- Script- and agent-friendly output: Stream text, write media directly to disk, emit structured JSON (
--output-format json) or compact TOON (--output-format toon), or filter fields inline with --jq.
- Stateless execution: Each invocation runs independently. Your agent supplies the context, chooses the model, and controls the next step.
Built for headless use by coding agents and assistant tools, with the same interface available to shell scripts and CI jobs. A single Go binary runs on macOS, Linux, and Windows.
Installation
macOS and Linux
curl -fsSL https://raw.githubusercontent.com/google-gemini/gemini-api-cli/main/scripts/install.sh | bash
Windows (PowerShell)
iwr -useb https://raw.githubusercontent.com/google-gemini/gemini-api-cli/main/scripts/install.ps1 | iex
Go install
Install the latest release with Go:
go install github.com/google-gemini/gemini-api-cli/cmd/gemini-api@latest
To build the current development version, use @main instead of @latest. Current main requires Go 1.26.10 or later (Go's automatic toolchain selection downloads the required version if needed).
Prebuilt binaries
Download prebuilt archives for macOS, Linux, and Windows from GitHub Releases and place gemini-api on your PATH.
Quick start
1. Configure your API key
Create an API key in Google AI Studio (see the Gemini API key docs) and make it available to your shell or your agent's subprocess environment:
export GEMINI_API_KEY="YOUR_API_KEY"
Workstation tip: To persist your key in your OS keychain (macOS Keychain, Linux Secret Service, or Windows Credential Manager) or ~/.config/gemini-api/config.yaml, run gemini-api configure --api-key "YOUR_API_KEY" or open the interactive form with gemini-api configure --interactive. Check your active configuration and credential source at any time with gemini-api whoami.
Verify your setup locally with --dry-run (no network call), then remove --dry-run to call the API:
gemini-api generate "Hello from my agent" --dry-run
gemini-api generate "Hello from my agent"
2. Give your agent instructions
Add the following block to your agent's instructions (AGENTS.md, CLAUDE.md, .cursorrules, or tool configuration):
You have access to gemini-api through the shell.
Use it to call Gemini models, generate or edit media, analyze files, or launch managed agents.
1. Inspect --help or --usage to choose a command, and --schema when building a --body JSON payload.
2. Preview API calls with --dry-run (or --dry-run --output-format json).
3. For discrete JSON output or --jq filtering on streaming commands (generate, agent run, agent status --stream), pass --stream=false --output-format json (--background on agent run returns a single interaction without streaming unless --stream is passed).
4. Capture returned file paths (from media commands) and interaction IDs (from agent/model runs) to continue multi-step tasks.
3. Put your agent to work
Prompt your host agent as usual:
Build a landing page for this app. Use Gemini to create a mascot image and a welcome voiceover, and launch a managed research agent to investigate competing products. Incorporate the assets and findings into the page.
Your agent chooses the commands, runs them in its shell, and uses the returned file paths and interaction IDs in its own workflow.
Command overview
Run gemini-api --help to see all top-level commands, or gemini-api <command> --help for command-specific flags and examples.
| Category |
Command |
Subcommands / Key Flags |
Description & default model |
| Create |
gemini-api generate |
-m, -i/--input, --stdin, --system, --stream=false, --body |
Text and multimodal generation (gemini-4-hydrogen) |
|
gemini-api image |
-m, -i/--input, --stdin, --out, --body |
Generate or edit images (gemini-nano-banana-2.1) |
|
gemini-api tts |
-f/--file, --stdin, --voice, --voice-prompt, --style, --multi-speaker, --out |
Text-to-speech audio generation (gemini-3.8-flash-tts) |
|
gemini-api music |
-m, -f/--file, --stdin, --out, --body |
Music generation (lyria-3.5) |
|
gemini-api video |
-m, -i/--input, --stdin, --async, --out, --body |
Conversational video generation and editing (gemini-omni-1.2-flash) |
| Understand |
gemini-api analyze |
-i/--input (repeatable), --stdin, --system, -m |
Ask questions about PDFs, images, audio, video, CSV/text files, or YouTube URLs (gemini-4-hydrogen) |
|
gemini-api transcribe |
-i/--input (repeatable), --format (md, text, json, srt), --out |
Transcribe audio or video to Markdown (md), plain text (text), JSON (json), or SRT captions (srt) (gemini-3.5-transcribe) |
| Manage |
gemini-api agent |
run, status, cancel, delete-interaction, create, list, get, delete |
Run interactions with models or managed agents (run, status, cancel) and manage agent definitions |
|
gemini-api files |
upload, list, get, generated-files-list, register, delete |
Upload, list, inspect, register, and delete files via the Files API (48-hour retention) |
|
gemini-api models |
(bare catalog), list (--all), get |
View the offline model catalog, or query live API models (list, get) |
|
gemini-api voices |
create, list (--all), get, delete |
Design, replicate, list, inspect, and delete custom voices |
|
gemini-api configure |
--api-key, --interactive, --output-format |
Configure authentication, global parameters, and persistent preferences |
|
gemini-api auth / whoami |
auth login, auth whoami, auth logout |
Manage stored credentials (auth) or inspect active authentication and configuration (whoami) |
| Advanced |
gemini-api environments |
create, list, get, delete, files (list, upload, download), connect, poll, serve |
Manage sandbox environments, upload/list/download environment files, or run self-hosted environments |
|
gemini-api credentials |
create, list, get, update, delete |
Manage stored server-side credentials for managed agents |
|
gemini-api webhooks |
create, list, get, update, ping, rotate-signing-secret, delete |
Manage webhook endpoints and signing secrets for event delivery |
|
gemini-api triggers |
list, get, update, run, list-executions, delete |
Inspect, run, update, and delete cron triggers for managed agents |
| Utility |
gemini-api explore / version |
— |
Launch the interactive command explorer (explore) or print the CLI version (version) |
Agent discovery and machine interface
Everything an agent needs to use gemini-api is discoverable from the binary itself, without external documentation or credentials:
| When an agent needs to… |
It runs… |
| Discover commands and flags |
gemini-api --help or gemini-api --usage |
| Inspect a request body schema |
gemini-api agent run --schema |
| Validate and preview a call offline |
gemini-api image "A robot mascot" --dry-run |
| Parse a complete structured response |
gemini-api generate "Hello" --stream=false --output-format json |
| Extract a single field inline |
gemini-api agent list --jq '.agents[].id' |
--usage outputs the complete command tree, flags, defaults, environment variables, and config keys as machine-readable KDL.
--schema prints the bundled JSON Schema (draft 2020-12) for any command that accepts a request body.
--dry-run validates flags and payloads and previews the HTTP request without credentials or network access (use --dry-run --output-format json for machine-parseable JSON request previews).
--no-interactive disables all interactive prompts and TUI forms.
--agent-mode (or GEMINI_CLI_AGENT_MODE=1) enables structured JSON error envelopes on stderr and defaults stdout to compact TOON output (--output-format json explicitly selects JSON).
- Exit codes distinguish success (
0), runtime/API failures (1), invalid usage/validation errors (2), and authentication/authorization failures (3).
Run gemini-api --help-global to see all global authentication, network, output, and diagnostic flags.
Agent workflows
1. Generate and edit creative assets
Coding agents like Codex, Claude Code, or Antigravity can generate images, speech, music, and video while building an app: