跳转到主要内容
使用本指南通过 CometAPI 作为 API 端点运行 Gemini CLI 官方参考:
模型可用性会随时间变化。请查看 CometAPI Models 页面 以了解当前可用的 Gemini 模型。

前提条件

要求详情
Node.js22+(推荐 LTS)
OSmacOS、Linux 或 Windows
CometAPI key来自你的 CometAPI Dashboard(以 sk- 开头)

设置

1

安装 Gemini CLI

npm install -g @google/gemini-cli
或通过 Homebrew 安装(macOS / Linux):
brew install gemini-cli
验证:
gemini --version
2

设置环境变量

export GEMINI_API_KEY="sk-your-cometapi-key"
export GOOGLE_GEMINI_BASE_URL="https://api.cometapi.com"
sk-your-cometapi-key 替换为你实际的 CometAPI key。
3

启动 Gemini CLI

cd your-project
gemini
首次启动时,系统会提示你选择主题、确认安全提示,并信任当前工作目录。

持久化环境变量

为了避免每次会话都重新导出,请将以下内容添加到你的 shell 配置中:
# Add to ~/.zshrc (macOS) or ~/.bashrc (Linux)
export GEMINI_API_KEY="sk-your-cometapi-key"
export GOOGLE_GEMINI_BASE_URL="https://api.cometapi.com"
重启终端以使更改生效。

故障排查

症状解决方法
Invalid API Key 错误确认 GEMINI_API_KEY 已正确设置。运行 echo $GEMINI_API_KEY 进行检查
fetch failed网络限制可能阻止连接。请尝试使用系统级代理
Node.js 版本错误Gemini CLI 需要 Node.js 22+。运行 node --version 进行检查
卸载npm uninstall -g @google/gemini-cli