@don_tech1: 如果你正用 Gemini 4 Neon,强烈建议给你的 Agent 装一个 Google 官方刚开源的小工具:gemini-api-cli。 这个新出的 google-gemini/gemini-api-cli(命令叫 gemini-ap…
摘要
Google 开源了零依赖的 Go 单文件命令行工具 gemini-api-cli,让 Codex、Claude Code 等编程 Agent 直接调用 Gemini 的多模态能力(生图、视频、TTS、字幕、文件分析等),实测可节省约 85.8% 的 Token 并提升近 2 倍速度。
查看缓存全文
缓存时间: 2026/11/24 03:13
如果你正用 Gemini 4 Neon,强烈建议给你的 Agent 装一个 Google 官方刚开源的小工具:gemini-api-cli。
这个新出的 google-gemini/gemini-api-cli(命令叫 gemini-api)是一个零依赖的 Go 单文件,专门给你的 AI Agent 当“多模态外挂”用的。
装上它、配个 API Key、再装上官方的 gemini-api-cli Skill,你的编程 Agent 直接就能在终端里干这些活:
- 一句话生图、改图(Nano Banana)、生视频(Veo)
- 合成多角色语音(TTS)、生成纯音乐配乐(Lyria)
- 分析本地 PDF、图片 OCR、甚至直接丢个 YouTube 链接让它看
- 音视频直接转带时间戳的 SRT 字幕,还能拉起后台 Deep Research
最有意思的是 Google DeepMind 工程师自己跑的实测数据:
以前让 Agent 调多模态能力,它得自己猜模型名、写临时 Python 脚本或拼 curl,动不动还把一堆 Base64 塞进上下文撑爆窗口。
换成这个 CLI + Skill 后,文件直接写进硬盘,终端只吐一个文件路径:
实测平均省了 85.8% 的 Token,跑完快了接近 2 倍。
也不用折腾常驻后台的 MCP 服务,不用配运行环境,原生自带 –help、–schema 和 –dry-run,Agent 拿起来就会用。
做全栈或者独立开发,一边写代码一边顺手让 Agent 把页面配图、音效、演示视频全部完成。
项目地址:http://github.com/google-gemini/gemini-api-cli… 官方 Skill:http://github.com/google-gemini/gemini-skills…
google-gemini/gemini-api-cli
Source: https://github.com/google-gemini/gemini-api-cli
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-runvalidates 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, rungemini-api configure --api-key "YOUR_API_KEY"or open the interactive form withgemini-api configure --interactive. Check your active configuration and credential source at any time withgemini-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' |
--usageoutputs the complete command tree, flags, defaults, environment variables, and config keys as machine-readable KDL.--schemaprints the bundled JSON Schema (draft 2020-12) for any command that accepts a request body.--dry-runvalidates flags and payloads and previews the HTTP request without credentials or network access (use--dry-run --output-format jsonfor machine-parseable JSON request previews).--no-interactivedisables all interactive prompts and TUI forms.--agent-mode(orGEMINI_CLI_AGENT_MODE=1) enables structured JSON error envelopes onstderrand defaultsstdoutto compact TOON output (--output-format jsonexplicitly 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:
# Generate an image and capture the written file path
MASCOT_PATH=$(gemini-api image "A friendly robot mascot, soft studio lighting" --out ./assets/mascot.jpg)
# Edit an existing image with -i / --input
gemini-api image "Add a winter scarf and snowy background" -i "$MASCOT_PATH" --out ./assets/mascot-winter.jpg
# Generate single-speaker or multi-speaker voiceovers
gemini-api tts "Welcome. Let's build something together." --out ./assets/welcome.wav
gemini-api tts "Alice: Welcome to the demo! Bob: Let's dive right in." \
--multi-speaker "Alice=Kore,Bob=Puck" \
--out ./assets/dialogue.wav
# Generate background music and video
gemini-api music "Warm ambient music for a product walkthrough" --out ./assets/
gemini-api video "A slow camera move through a sunlit workshop" --out ./assets/
Media commands write files locally and print only the written file path to stdout. When --out points to a directory (or is omitted), the CLI names the file automatically using the file extension that matches the API’s returned MIME type (for example, .jpg for image/jpeg, .wav for audio/wav, .mp3 for audio/mpeg, and .mp4 for video/mp4).
2. Analyze documents and transcribe recordings
Assistants like OpenClaw or Hermes can turn documents, media files, and YouTube URLs into answers and deliverables:
# Analyze a PDF or compare multiple images
gemini-api analyze --input product-brief.pdf "What should we build first, and why?" > plan.md
gemini-api analyze --input before.png --input after.png "Summarize the visual design changes"
# Transcribe audio or video (valid formats: md, text, json, srt)
gemini-api transcribe --input interview.mp4 --format srt --out interview.srt
For larger media files (over ~14 MB raw / 20 MB base64-encoded), upload once with files upload --wait and reuse the returned files/<id> URI across analyze, transcribe, generate, image, video, or agent run:
FILE_URI=$(gemini-api files upload interview.mp4 --wait --output-format json --jq '.name')
gemini-api analyze --input "$FILE_URI" "List the key action items with timestamps"
3. Launch and poll a background managed agent
Delegate multi-step research or coding tasks to a Gemini managed agent such as Deep Research. Pass --background so the CLI returns a single interaction (no stream, unless --stream is passed) with the interaction ID immediately instead of holding open an SSE stream:
INTERACTION_ID=$(gemini-api agent run "Research battery recycling approaches and cite sources" \
--agent deep-research-preview-04-2026 \
--background \
--jq '.id')
echo "Started interaction: $INTERACTION_ID"
Check progress or retrieve the finished output using the returned INTERACTION_ID:
gemini-api agent status "$INTERACTION_ID" --stream=false --output-format json
You can also stream live progress events (gemini-api agent status "$INTERACTION_ID" --stream) or cancel an active run (gemini-api agent cancel "$INTERACTION_ID").
4. Choose the right model
Use --model (-m) on generation and analysis commands to pick a model for reasoning, fast text, multimodal understanding, or media generation:
# View the curated offline model catalog grouped by capability
gemini-api models
# Query all live models available to your API key (--all auto-paginates across pages)
gemini-api models list --all
gemini-api models get gemini-4-hydrogen
# Run a prompt with a specific model
gemini-api generate "Review this approach: cache immutable responses by content hash" --model gemini-4-hydrogen
Go deeper: custom request bodies (--schema to --body)
Short flags cover common tasks; --body gives your agent full access to the underlying Interactions API request schema while keeping the CLI’s file output and error handling.
First, inspect the schema for image:
gemini-api image --schema > image-schema.json
Next, create hero-image.json to select gemini-nano-banana-2.1, request a 16:9 image at 2K size (image_size: "512", "1K", "2K", or "4K"), and disable server-side interaction storage ("store": false):
cat > hero-image.json <<'JSON'
{
"model": "gemini-nano-banana-2.1",
"input": "A friendly robot mascot in a sunlit workshop, composed on the right with uncluttered space on the left for a landing page headline. No text or watermark.",
"response_format": {
"type": "image",
"aspect_ratio": "16:9",
"image_size": "2K"
},
"store": false,
"stream": false
}
JSON
Preview the exact HTTP payload with --dry-run, then execute the request:
gemini-api image --body @hero-image.json --out ./assets/hero.jpg --dry-run --output-format json
gemini-api image --body @hero-image.json --out ./assets/hero.jpg --output-format json
With --output-format json, the CLI writes the image to disk and returns structured artifact metadata on stdout:
{
"kind": "image",
"mime_type": "image/jpeg",
"path": "/path/to/project/assets/hero.jpg",
"size_bytes": 2914159,
"status": "completed"
}
--out controls the local file destination; response_format controls what the model generates (pass --raw-response instead of --out if you want the full raw API response envelope). The same --schema to --body workflow applies to gemini-api agent run and other commands when configuring system_instruction, tools, structured JSON response_format.schema, or stateful multi-turn continuations via previous_interaction_id:
# Turn 1: Run a non-streaming interaction and capture its ID
TURN1_ID=$(gemini-api generate "Propose 3 database indexing strategies for a time-series log table." \
--stream=false --jq '.id')
# Turn 2: Continue the conversation using previous_interaction_id
gemini-api agent run "Compare strategy #2 and #3 for write-heavy workloads." \
--body "{\"previous_interaction_id\": \"$TURN1_ID\"}" \
--stream=false
The CLI stores no local conversation state—server-side interactions and uploaded files manage their own retention on the API, and your workflow keeps only the IDs it wants to reuse.
Status, feedback, and contributions
gemini-apiis in beta and evolving alongside the Gemini Interactions API. Breaking changes may occur between releases; we recommend pinning to a specific release version in CI and automated workflows.
- Bugs & feedback: Found a bug or have feedback on
gemini-api? Please open an issue in GitHub Issues. - Contributions (pull requests not accepted): At this time, we are not accepting external pull requests or code contributions, and any opened PRs will be closed without review — see CONTRIBUTING.md.
- Releases: Browse changelog notes and prebuilt binaries on GitHub Releases.
Licensing & Disclaimer
Copyright 2026 Google LLC
All software is licensed under the Apache License, Version 2.0 (Apache 2.0); you may not use this file except in compliance with the Apache 2.0 license. You may obtain a copy of the Apache 2.0 license at: https://www.apache.org/licenses/LICENSE-2.0
All other materials are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0). You may obtain a copy of the CC-BY license at: https://creativecommons.org/licenses/by/4.0/legalcode.
Dmitry Lyalin (@LyalinDotCom): If you’re building things w/Gemini 4 Neon that could benefit from easy access to Gemini’s ability to do video analysis, OCR, or multi-media gen (tts, music, videos, images) you will be blown away by simple installing
gemini-cli, setting an API key & installing skillIt’s even
相似文章
@mingzi206: 卧槽!Gemini 4 Neon 封神还不够,Google 居然偷偷把全套多模态物理外挂给开源了! 官方刚刚上线核弹级终端神器:gemini-api-cli。 简单粗暴到离谱:你在终端敲一行命令,就能直接把 Gemini 逆天的视频理解、…
Google 官方开源了纯 Go 打造的终端工具 gemini-api-cli,一行命令即可在终端调用 Gemini 的图像生成、TTS、视频理解、OCR 及音视频生成等全套多模态能力,也可作为 Claude Code、Codex 等 Agent 的后端素材库。
@ohouhou717: 卧槽,Google 又开始大撒币了! Gemini 4 Hydrogen 居然能免费白嫖 API 了! 100 万上下文,每天大概 1500 次额度,搞 Agent 简直爽翻。 直接去 AI Studio 建个 Key,模型填 gemin…
Google 开始免费提供 Gemini 4 Hydrogen 模型的 API 额度,拥有 100 万上下文窗口,每天约 1500 次调用,用户只需在 AI Studio 创建 Key 即可使用,非常适合开发 Agent 应用。
@stormzhangV: Google 官方开源的这个项目,建议所有使用 agy + neon 的用户都安装下。 仓库里主要有 2 个核心 Skill - deep-research(仅 21 行): 极简的多 Agent 并行深度调研指南。规定了 5 步流水线 …
Google 官方开源了 Gemini 团队的 DemoLab 仓库,包含 deep-research(多 Agent 并行深度调研,盲评胜率超 90%)和 gemini-frontend-design(反 AI 味前端设计规范,胜率 67%-75%)两个核心 Skill,支持通过多种 AI 编码助手和 CLI 安装。
google/agents-cli
Google 发布了 `agents-cli`,这是一个命令行工具和技能集,用于在 Gemini Enterprise Agent 平台上构建、部署和管理企业级代理,旨在与 Claude Code 和 Codex 等流行编码助手集成。
Gemini Agent(阅读约18分钟)
Google Cloud 在 Gemini at Work 2026 上发布 Gemini agent——一个面向工作场景的统一智能体,可在单一提示框中回答问题、处理知识工作、创建媒体、编写并运行代码,并深度集成 Google Workspace、行业专属技能与企业级安全治理能力。