Authentication Error Fixes

Resolve authentication issues and API key problems when using Gemini CLI.

Common Authentication Errors

❌ "API key not provided"

Error: GOOGLE_AI_API_KEY environment variable is not set or accessible

Solutions:

1. Set environment variable:

# Linux/macOS

export GOOGLE_AI_API_KEY="your_api_key_here"

# Windows (Command Prompt)

set GOOGLE_AI_API_KEY=your_api_key_here

# Windows (PowerShell)

$env:GOOGLE_AI_API_KEY="your_api_key_here"

❌ "Invalid API key"

Error: API key format is incorrect or key is invalid

Solutions:

1. Verify API key format:

  • Should start with "AIza" followed by 35 characters
  • Total length should be 39 characters
  • Contains only alphanumeric characters and dashes

2. Generate a new API key:

Visit Google AI Studio to create a new API key.

Quick Fixes

Check environment variable

echo $GOOGLE_AI_API_KEY

Next Steps

Still having authentication issues? Try these resources: