Skip to content
,

Gemini API CLI Guide (2026): Install gemini-api and Use Every Command

8–12 minutes
Woman in a glass-walled office holding a tablet with a GEMINI API CLI card, hook Gemini from terminal

Google now ships an official command-line tool for the Gemini API. It is called gemini-api, and it lets you generate text, images, speech, music and video, analyze files and run Deep Research agents straight from your terminal, with no Python or JavaScript project to set up.

This guide shows how to install it on Windows, macOS and Linux, add your API key, and use every main command with copy-paste examples.

It also covers JSON output for scripts, the agent skill for Claude Code and other coding agents, exit codes and the common errors. Everything follows the official google-gemini/gemini-api-cli repository as of December 2026.

TL;DR

  • Install (macOS/Linux): curl -fsSL https://raw.githubusercontent.com/google-gemini/gemini-api-cli/main/scripts/install.sh | bash
  • Auth: export GEMINI_API_KEY=... or gemini-api configure --interactive.
  • Text: gemini-api generate "Explain RAG in 3 lines" (default model gemini-4-neon).
  • Media: image, tts, music, video, analyze and transcribe commands.
  • Scripts: --output-format json, --jq, --dry-run, and exit codes 0/1/2/3.
  • Status: beta, so pin a release in CI. It is not the same tool as Gemini CLI.

What the Gemini API CLI Is

The Gemini API CLI is a single binary, written in Go, that wraps the Gemini API. Each command maps to one API feature and picks a sensible default model, so a one-line command replaces a short SDK script.

It is easy to mix up with two other Google tools, so here is how they differ:

Tool Command What it does
Gemini API CLI gemini-api Calls Gemini API features (text, media, files, agents) with your API key
Gemini CLI gemini Interactive coding agent; now aimed at enterprise customers
Google Gen AI SDKs Python, JS, Go, Java libraries Build the API into your own apps

If you want a coding agent, read Claude Code vs Gemini CLI. If you want to call Gemini models from the shell or a script, the Gemini API CLI is the right tool.

The project is open source under Apache 2.0. It is in beta, which means commands and flags can still change between releases, and the maintainers do not accept outside pull requests.

Install gemini-api

There are three ways to install it. All of them put a gemini-api command on your PATH.

macOS and Linux

  1. Run the install script in a terminal:
    curl -fsSL https://raw.githubusercontent.com/google-gemini/gemini-api-cli/main/scripts/install.sh | bash
  2. Open a new terminal so your shell picks up the updated PATH.
  3. Check the install with gemini-api version.

Windows (PowerShell)

  1. Open PowerShell (not Command Prompt).
  2. Run the Windows installer:
    iwr -useb https://raw.githubusercontent.com/google-gemini/gemini-api-cli/main/scripts/install.ps1 | iex
  3. Restart PowerShell and run gemini-api version.

With Go

If you already have Go installed, build it from source:

go install github.com/google-gemini/gemini-api-cli/cmd/gemini-api@latest

Make sure your Go bin folder (usually ~/go/bin) is on your PATH. Because the tool is in beta, replace @latest with a release tag when you install it on servers or in CI, so an update cannot break your scripts.

Add Your API Key

You need a Gemini API key from Google AI Studio. If you do not have one yet, follow our Gemini API key guide. The free tier is enough to try every text command; see Gemini API pricing and free tier for the limits on media models.

The CLI accepts the key in two ways:

  1. Environment variable (good for CI):
    # macOS / Linux
    export GEMINI_API_KEY="your-key"
    
    # Windows PowerShell
    $env:GEMINI_API_KEY="your-key"
  2. Saved config (good for your own PC):
    gemini-api configure --interactive

    This prompts for the key and stores it in your operating system keychain, or in ~/.config/gemini-api/config.yaml when no keychain is available. You can also pass it directly with gemini-api configure --api-key YOUR_KEY, but that leaves the key in your shell history.

  3. Test without spending tokens:
    gemini-api generate "Hello" --dry-run

    A dry run prints the request it would send, so you can check the model and settings before a real call.

Run gemini-api auth whoami to see which credentials the CLI is using. Never commit the key or the config file to Git.

Generate Text

The generate command sends a prompt and prints the reply. It uses gemini-4-neon by default (see our Gemini 4 Neon guide).

gemini-api generate "Write a haiku about GPUs"

Replies stream to the terminal as they arrive. Add --stream=false to wait for the full answer, which is easier to pipe into other tools:

gemini-api generate "Summarize this changelog" --stream=false > summary.txt

To pick another model, list what your key can use and pass its name:

gemini-api models list
gemini-api models list --all
gemini-api models get gemini-4-neon

For a multi-turn chat, keep the interaction id from the previous reply and send it back as previous_interaction_id, so the model sees the earlier turns. This works the same way as the Gemini Interactions API.

For full control, pass a JSON request body. Print the expected shape with --schema, write your file, then send it:

gemini-api generate --schema > generate.schema.json
gemini-api generate --body @request.json

Images, Speech, Music and Video

Each media type has its own command and default model:

Command Default model Example
image gemini-nano-banana-2.1 gemini-api image "a lime green robot reading a book"
tts gemini-3.8-flash-tts gemini-api tts "Welcome to the show" --voice Kore
music lyria-3.5 gemini-api music "calm lo-fi beat for studying"
video gemini-omni-1.2-flash gemini-api video "a paper boat on a rainy street"

Text to speech with several voices

List the available voices with gemini-api voices. For a dialogue, map each speaker to a voice:

gemini-api tts "Alice: Did you see the release? Bob: Yes, it ships today." \
  --multi-speaker "Alice=Kore,Bob=Puck"

Our Gemini TTS API tutorial explains voices and style prompts in more depth, and the Gemini Omni API tutorial covers video generation settings.

Image, music and video models usually cost more than text and may not be on the free tier. Run the command with --dry-run first if you are unsure which model it will call.

Analyze and Transcribe Files

The analyze command sends files with your prompt. Use -i once per input. It accepts PDFs, images, audio, video and YouTube links:

gemini-api analyze "List the key numbers in this report" -i report.pdf
gemini-api analyze "What changed between these screenshots?" -i before.png -i after.png
gemini-api analyze "Summarize this talk" -i https://www.youtube.com/watch?v=VIDEO_ID

The transcribe command turns audio or video into text. Pick the format you need:

gemini-api transcribe meeting.mp3 --format md
gemini-api transcribe interview.mp4 --format srt > interview.srt

Supported formats are md, text, json and srt. SRT output drops straight into most video editors as subtitles.

Large files

Files above roughly 14 MB raw (about 20 MB once base64 encoded) are too big to send inline. Upload them first with the Files API:

gemini-api files upload lecture.mp4 --wait

--wait blocks until the file has finished processing. Uploaded files are kept for 48 hours, then deleted automatically.

Run Deep Research Agents

The agent commands start long-running agents such as Deep Research. Because a research run can take several minutes, start it in the background and save its id:

ID=$(gemini-api agent run "Compare open-weight coding models released in 2026" \
  --agent deep-research-preview-04-2026 --background --jq '.id')

gemini-api agent status "$ID"
gemini-api agent cancel "$ID"

Check status until the run finishes, then read the report from its output. Cancel runs you no longer need, since agent work is billed as it goes.

Use It in Scripts and CI

The CLI was built to be scripted, both by people and by AI agents. These flags matter most:

Flag What it does
--output-format json Machine-readable output (toon is a compact alternative for LLM prompts)
--jq '<filter>' Filters JSON output with a jq expression, no separate jq install needed
--dry-run Prints the request without sending it
--stream=false Waits for the full reply instead of streaming
--no-interactive Never prompts; fails instead (use in CI)
--agent-mode Output tuned for AI agents; same as GEMINI_CLI_AGENT_MODE=1
--raw-response Prints the API response exactly as returned
--usage Prints a command’s full usage spec (in KDL format)
--schema Prints the JSON Schema for a request body

The exit code tells your script what went wrong:

Exit code Meaning Typical fix
0 Success None
1 Runtime error (API error, network, quota) Retry with backoff, check quota
2 Usage error (bad flag or argument) Fix the command
3 Authentication error Set or replace the API key

A simple GitHub Actions step looks like this:

- name: Summarize release notes
  env:
    GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
  run: |
    gemini-api generate "Summarize: $(cat CHANGELOG.md | head -100)" \
      --stream=false --no-interactive > summary.md

For bulk jobs with hundreds of prompts, the Gemini Batch API is cheaper than a loop of single calls.

Install the Agent Skill

The CLI can install a skill that teaches coding agents how to use it. Preview first, then install:

gemini-api install-skill --agent claude-code --dry-run
gemini-api install-skill --agent claude-code
gemini-api install-skill --agent claude-code --global

Without --global, the skill goes into the current project. With it, the skill is available in every project. After that, you can ask Claude Code to “generate a cover image with the Gemini API” and it will call gemini-api image for you. See our Claude Skills guide for how skills load.

Command Cheat Sheet

Command Purpose
generate Text generation and chat
image / tts / music / video Media generation
analyze Prompt with PDFs, images, audio, video or YouTube
transcribe Speech to text (md, text, json, srt)
agent run / status / cancel Long-running agents like Deep Research
files upload Upload large files (kept 48 hours)
models list / get See available models
voices List TTS voices
configure / auth whoami Set and check credentials
environments, credentials, webhooks, triggers Manage advanced API resources
explore / version Browse commands, show the installed version

Add --help to any command for its flags.

Troubleshooting

gemini-api: command not found

Open a new terminal after installing. For a Go install, add ~/go/bin to your PATH. On Windows, restart PowerShell.

Exit code 3 or “API key not valid”

Check gemini-api auth whoami. If an old GEMINI_API_KEY is still set in your shell or CI secrets, replace or unset it. Create a fresh key in AI Studio if needed.

429 or quota errors (exit code 1)

You hit a rate limit. Wait and retry, switch to a lighter model, or enable billing. Our Gemini API errors guide lists each code.

Request too large

Upload the file with gemini-api files upload FILE --wait and reference it, instead of passing a big file inline.

A script broke after an update

The CLI is in beta and can change. Pin a release version in installs and CI, and read the release notes before upgrading.

The command hangs in CI

It may be waiting for a prompt. Add --no-interactive and set GEMINI_API_KEY as a secret.

FAQ

Is the Gemini API CLI free?

The tool is free and open source. API calls use your Gemini API quota, so free-tier limits and paid pricing apply as usual.

Is gemini-api the same as Gemini CLI?

No. gemini-api calls Gemini API features from the shell. Gemini CLI (gemini) is an interactive coding agent.

Does it work on Windows?

Yes. Install it with the PowerShell script or with go install.

Where is my API key stored?

In your OS keychain when available, otherwise in ~/.config/gemini-api/config.yaml.

Can I get JSON output?

Yes. Add --output-format json, and use --jq to pull out one field.

Can Claude Code use it?

Yes. Run gemini-api install-skill --agent claude-code and Claude Code learns the commands.

Is it stable enough for production?

It is in beta. Pin a version and test upgrades before rolling them out, or use the official SDKs, as in our Gemini API Python tutorial, for long-lived apps.

Sources

Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Woman in a glass-walled office holding a tablet with a GEMINI API CLI card, hook Gemini from terminal