跳轉到主要內容

Documentation Index

Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt

Use this file to discover all available pages before exploring further.

使用本指南可讓你以 CometAPI 作為 API 端點執行 Gemini CLI 官方參考資料:
模型可用性會隨時間變動。請查看 CometAPI Models page 以確認可用的 Gemini 模型。

先決條件

RequirementDetails
Node.js22+(建議使用 LTS)
OSmacOS、Linux 或 Windows
CometAPI key來自你的 CometAPI Dashboard(以 sk- 開頭)

設定

1

Install Gemini CLI

npm install -g @google/gemini-cli
或透過 Homebrew 安裝(macOS / Linux):
brew install gemini-cli
驗證:
gemini --version
2

Set environment variables

export GEMINI_API_KEY="sk-your-cometapi-key"
export GOOGLE_GEMINI_BASE_URL="https://api.cometapi.com"
sk-your-cometapi-key 替換為你實際的 CometAPI key。
3

Start 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"
重新啟動終端機以讓變更生效。

疑難排解

SymptomFix
Invalid API Key error確認 GEMINI_API_KEY 已正確設定。執行 echo $GEMINI_API_KEY 進行檢查
fetch failed網路限制可能會阻擋連線。請嘗試使用系統層級代理
Wrong Node.js versionGemini CLI 需要 Node.js 22+。執行 node --version 進行檢查
Uninstallnpm uninstall -g @google/gemini-cli