跪拜 Guibai
← All articles
Gemini · ChatGLM (Zhipu) · Agent

Google's `gemini-api` CLI Lets You Run Gemini 4 Neon Inside Claude Code, Codex, and Pi

By 沉默王二 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

This removes the need to switch harnesses to get Gemini 4 Neon and Google's multimodal models inside existing Claude Code or Codex workflows. It also shows an alternative to MCP that keeps agent context small, which matters for long sessions where context inflation is the real bottleneck.

Summary

Google has shipped `gemini-api`, a Go-compiled single-file executable that exposes Gemini 4 Neon and the rest of its multimodal stack to third-party coding agents. Unlike the interactive `gemini-cli`, this is a stateless command-line tool: the host agent, whether Claude Code, Codex, or Pi, keeps the context and execution plan, and calls `gemini-api` subcommands for text, image generation, TTS, transcription, file analysis, and hosted agents. The binary is Apache 2.0 and runs on macOS, Linux, and Windows.

Installation is a single curl command or `go install`, followed by setting a `GEMINI_API_KEY` from AI Studio. Plugin installs exist for Claude Code and Codex, and four optional rules can go into `CLAUDE.md` or `AGENTS.md` instead. Use cases include cross-reviewing code with Gemini 4 Neon at `xhigh` thinking, generating cover images and podcast intros, end-to-end voice testing without a microphone using fake media streams, background deep research with `agent run --background`, and analysis of large PDFs and meeting recordings through the Files API with a 14 MB inline threshold and 48-hour retention.

Under the hood, every subcommand hits the same `POST /v1beta/interactions` endpoint, Google's Interactions API. The CLI embeds its documentation in the binary and queries it on demand instead of loading all tool specs into the agent's context like MCP, and writes media files to disk rather than returning Base64 strings. A built-in `gojq` and TOON output shrink token usage. Source code also documents a BYOS mode, `gemini-api environments connect`, for running agent sandboxes on your own machines when code must not leave the intranet.

Takeaways
— `gemini-api` is a stateless, Go-compiled single-file CLI, Apache 2.0, available for macOS, Linux, and Windows.
— The host agent (Claude Code, Codex, Pi) keeps the context; `gemini-api` handles individual calls via subcommands.
— Default text model is Gemini 4 Hydrogen; switching to Neon or Carbon uses `-m` flag. Image gen defaults to `gemini-nano-banana-2.1`, TTS to `gemini-3.8-flash-tts`, music to `lyria-3.5`, video to `gemini-omni-1.2-flash`.
— `agent run` supports `--background` with `deep-research-preview-04-2026` and `antigravity-preview-09-2026` in a cloud sandbox.
— Install with `curl -fsSL https://raw.githubusercontent.com/google-gemini/gemini-api-cli/main/scripts/install.sh | bash` or `go install github.com/google-gemini/gemini-api-cli/cmd/gemini-api@latest`.
— API key goes in the environment variable `GEMINI_API_KEY` or system keychain; the env var wins over keychain.
— Free-tier key: TTS works (39 tokens, 75388-byte WAV), but `gemini-4-neon` and image generation return 429 with quota 0.
— `--dry-run` validates commands offline without network, keychain access, or token consumption.
— File uploads: files up to 14 MB go inline; larger files use Files API with 48h retention and `files/<id>` references.
— CLI's media commands write files to disk and print only paths to stdout, avoiding context bloat.
Conclusions

The on-demand documentation and disk-based media output directly attack context inflation, a known pain with MCP; this suggests Google expects agent sessions to be long enough that tool specs and Base64 media are the real cost.

BYOS support signals a concession to enterprises that will not upload proprietary code to a third-party cloud sandbox; without it, the hosted agent feature would be a non-starter in many organizations.

Free-tier returns 429 on flagship models, so the tool's actual value sits behind a paid API key; for hobbyists, it is a teaser rather than a complete replacement.

Concepts & terms
Interactions API
Google's unified protocol endpoint at `POST /v1beta/interactions` that handles single-turn generation, multimodal media, multi-turn state, and hosted agents under one schema.
BYOS
Bring Your Own Sandbox: a mode in `gemini-api` that lets you connect your own intranet container or cloud host as the execution environment via `gemini-api environments connect`, instead of running agents in Google's cloud sandbox.
TOON output
A token-efficient output format (based on gotoon) with fewer symbols, used when `--agent-mode` is set, to reduce token consumption in agent contexts; errors are returned as structured JSON on stderr.
From the discussion
Featured comments
Yafeiml

Does this mean Google AI members can use third-party code agents?

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗