Authenticate with a Gemini API key

authentication

// what it does

Generate a key in Google AI Studio and export it as GEMINI_API_KEY; the CLI picks it up on startup with no browser flow. This is the simplest option for scripts and CI where interactive OAuth is impossible. Persist it in ~/.zshrc, ~/.bashrc, or ~/.gemini/.env.

// shell

$ export GEMINI_API_KEY=your-api-key
$ echo 'GEMINI_API_KEY=your-api-key' >> ~/.gemini/.env

// gotcha

GEMINI_API_KEY takes precedence over a cached Google login, so exporting it silently switches you off your subscription quota onto pay-as-you-go API billing. Unset it when you want to go back to the OAuth free tier.

// resources