The Gemini CLI fails to detect the GEMINI_API_KEY environment variable, even after setting and verifying it in the shell. When choosing “Gemini API Key” from the /auth menu, the CLI responds with:
GEMINI_API_KEY environment variable not found. Add that to your .env and try again, no reload needed!
However, the variable is correctly exported in .zshrc and visible via echo $GEMINI_API_KEY.
Client information
- OS: macOS
- Installed via: npm install -g @google/gemini-cli
- Output of /about (please replace with your actual output):
CLI Version: 0.1.3-rc.1
Git Commit: 382486e (local modifications)
Model: gemini-2.5-pro
Sandbox: no sandbox
OS: darwin arm64
Node version: v22.14.0
Additional context
I followed the instructions for advanced use with an API key from the official Gemini CLI README.
Steps taken:
- Generated a key in Google AI Studio.
- Added export GEMINI_API_KEY="REDACTED" to ~/.zshrc.
- Ran source ~/.zshrc.
- Verified with echo $GEMINI_API_KEY (value is shown correctly).
- Ran /auth in the CLI and selected “Gemini API Key.”
- Received the error stating that GEMINI_API_KEY environment variable was not found.
Expected behavior:
Gemini CLI should recognize the environment variable and authenticate via API key.
The Gemini CLI fails to detect the GEMINI_API_KEY environment variable, even after setting and verifying it in the shell. When choosing “Gemini API Key” from the /auth menu, the CLI responds with:
GEMINI_API_KEY environment variable not found. Add that to your .env and try again, no reload needed!
However, the variable is correctly exported in .zshrc and visible via echo $GEMINI_API_KEY.
Client information
CLI Version: 0.1.3-rc.1
Git Commit: 382486e (local modifications)
Model: gemini-2.5-pro
Sandbox: no sandbox
OS: darwin arm64
Node version: v22.14.0
Additional context
I followed the instructions for advanced use with an API key from the official Gemini CLI README.
Steps taken:
Expected behavior:
Gemini CLI should recognize the environment variable and authenticate via API key.