Overview
To use Gemini CLI, you need to authenticate with Google. This guide helps you choose the best authentication method based on your account type and use case.Quick Start: Most users should start with Login with Google for the simplest setup.
Choose Your Authentication Method
Select the method that matches your situation:| User Type / Scenario | Recommended Method | Google Cloud Project Required |
|---|---|---|
| Individual Google accounts | Login with Google | No, with exceptions |
| Organization users (company, school, Workspace) | Login with Google | Yes |
| AI Studio user with Gemini API key | Use Gemini API Key | No |
| Google Cloud Vertex AI user | Vertex AI | Yes |
| Headless/non-interactive mode | API Key or Vertex AI | Depends on method |
Account Types Explained
- Individual Accounts
- Organization Accounts
Individual Google accounts include:
- Free tier accounts (Gemini Code Assist for individuals)
- Paid subscriptions (Google AI Pro and Ultra)
- Personal Gmail accounts
- 60 requests/min
- 1,000 requests/day
Login with Google
The simplest authentication method for local development. Requires a web browser that can communicate with your terminal.Select Login with Google
When prompted “How would you like to authenticate for this project?”, select Login with Google.Gemini CLI will open a login prompt in your web browser.
Google AI Pro/Ultra subscribers: Use the Google account associated with your subscription.
Do I Need a Google Cloud Project?
Most individual accounts don’t require a Google Cloud project. However, you’ll need one if:- You’re using a company, school, or Google Workspace account
- You have a Gemini Code Assist license from the Google Developer Program
- You have a Gemini Code Assist subscription
Gemini API Key
Use an API key from Google AI Studio if you prefer not to authenticate with your Google account directly.Obtain API Key
Get your API key from Google AI Studio.
Set Environment Variable
API Key Benefits
- Free tier: 1000 requests/day with Gemini 3 (mix of flash and pro)
- Model selection: Choose specific Gemini models
- Usage-based billing: Upgrade for higher limits when needed
Vertex AI
For enterprise teams and production workloads using Google Cloud’s Vertex AI platform.All Vertex AI authentication methods require setting
GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION.Prerequisites
Set required environment variables for all Vertex AI methods:Method A: Application Default Credentials (ADC)
Best if you have Google Cloud CLI installed.Configure Project
Method B: Service Account JSON Key
Ideal for non-interactive environments, CI/CD pipelines, or restricted environments.Create Service Account
Create a service account and key and download the JSON file.Assign the Vertex AI User role to the service account.
Configure Project
Method C: Google Cloud API Key
Obtain API Key
Get an API Key from Google Cloud.
Configure Project
If you see errors like “API keys are not supported by this API…”, your organization might restrict API key usage. Try other Vertex AI authentication methods instead.
Set Google Cloud Project
Required for organization accounts and Vertex AI authentication.Find Your Project ID
Find your Google Cloud Project ID in the Google Cloud Console.
Enable Gemini API
Enable the Gemini for Cloud API for your project.
Configure IAM Access
Configure necessary IAM access permissions for your user or service account.
Set Environment Variable
Gemini CLI checks for
GOOGLE_CLOUD_PROJECT first, then falls back to GOOGLE_CLOUD_PROJECT_ID.Persisting Environment Variables
Avoid setting environment variables for every terminal session by persisting them:Method 1: Shell Configuration File
Add environment variables to your shell’s startup file:Method 2: .env File (Recommended)
Create a.gemini/.env file in your project or home directory. Gemini CLI automatically loads variables from the first .env file it finds.
Gemini CLI searches for
.env files starting from the current directory, then up the directory tree, and finally in ~/.gemini/.env.Google Cloud Environments
When running Gemini CLI in certain Google Cloud environments, authentication is automatic:Cloud Shell
Gemini CLI automatically authenticates using your Cloud Shell credentials.
Compute Engine
Gemini CLI automatically uses Application Default Credentials (ADC) from the environment’s metadata server.
Headless Mode
For headless/non-interactive mode, Gemini CLI uses your existing authentication if credentials are cached. If you haven’t logged in yet, you must configure authentication using environment variables:Troubleshooting
Authentication failed
Authentication failed
- Verify your credentials are correct
- Check that required environment variables are set
- Ensure you’ve selected the correct authentication method
- Try clearing cached credentials and re-authenticating
Google Cloud project errors
Google Cloud project errors
- Verify the project ID is correct
- Ensure the Gemini for Cloud API is enabled
- Check that your account has the necessary IAM permissions
- Confirm
GOOGLE_CLOUD_PROJECTis set correctly
API key not working
API key not working
- Verify the API key is copied correctly (no extra spaces)
- Check that the API key hasn’t expired or been revoked
- Ensure you’re using the correct API key for your chosen method (Gemini API vs Vertex AI)
- For Vertex AI API keys, verify your organization allows API key usage
Service account permissions
Service account permissions
- Ensure the service account has the “Vertex AI User” role
- Verify the JSON key file path is correct
- Check that the key file is readable by your user
- Confirm
GOOGLE_APPLICATION_CREDENTIALSpoints to a valid JSON file
Next Steps
Quick Start Guide
Get to your first working command in minutes
Quotas and Pricing
Learn about quotas, pricing, and terms of service