gemini-api 给 agent 的说明书模板和十条命令速查

S1哥 今日赠品 · 2026-10-31

配套教程:待补

来源:Google 官方 GitHub 仓库 google-gemini/gemini-api-cli 的 README。说明书模板的英文是 README 里的官方块;十条命令里的例子来自 README 示例,模型和参数以仓库最新版为准。

一、贴进 AGENTS.md / CLAUDE.md / .cursorrules 的官方说明块
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.

二、十条命令速查
1. 配 Key:export GEMINI_API_KEY="YOUR_API_KEY",或 gemini-api configure --api-key "YOUR_API_KEY"
2. 看当前配置:gemini-api whoami
3. 离线预览:gemini-api generate "Hello from my agent" --dry-run
4. 画图:gemini-api image "A friendly robot mascot, soft studio lighting" --out ./assets/mascot.jpg
5. 改图:gemini-api image "Add a winter scarf and snowy background" -i ./assets/mascot.jpg --out ./assets/mascot-winter.jpg
6. 配音:gemini-api tts "Welcome. Let's build something together." --out ./assets/welcome.wav
7. 音乐:gemini-api music "Warm ambient music for a product walkthrough" --out ./assets/
8. 分析文件:gemini-api analyze --input product-brief.pdf "What should we build first, and why?"
9. 转字幕:gemini-api transcribe --input interview.mp4 --format srt --out interview.srt
10. 后台调研:gemini-api agent run "Research battery recycling approaches and cite sources" --agent deep-research-preview-04-2026 --background --jq '.id',之后 gemini-api agent status 编号 --stream=false --output-format json

三、给 agent 的中文吩咐模板(S1哥 写的)
1. 先用 --dry-run 把要发的请求给我看,我确认再真正调用
2. 每次只生成一个文件,把文件路径告诉我
3. 超过 14 MB 的文件先 files upload --wait,再分析
4. 遇到退出码 3 就停下告诉我是认证问题,不要反复重试

四、退出码和提醒
1. 0 成功,1 运行或接口失败,2 用法错误,3 认证失败
2. 工具是实验性预览,版本间可能有变化,建议固定版本
3. agent 拿着你的 Key 能替你花钱,先 dry-run,再放权
S1哥(X @swordBluesy)每天一篇 AI 官方文档编译教程,每篇送一份赠品。粉丝群:t.me/haohanlab|关注 @swordBluesy