Skip to content

GEMINI_API_KEY not detected by Gemini CLI despite being exported in shell environment #1560

Description

@danielraffel

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:

  1. Generated a key in Google AI Studio.
  2. Added export GEMINI_API_KEY="REDACTED" to ~/.zshrc.
  3. Ran source ~/.zshrc.
  4. Verified with echo $GEMINI_API_KEY (value is shown correctly).
  5. Ran /auth in the CLI and selected “Gemini API Key.”
  6. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1Important and should be addressed in the near term.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions