Overview
Google Gemini authentication allows you to access Google Cloud AI services including Gemini Code Assist and Google One AI features. The CLI Proxy API supports OAuth 2.0 authentication with automatic project setup and onboarding.Prerequisites
Before authenticating with Gemini, ensure you have:- A Google account with access to:
- Google Cloud Platform (GCP) projects for Code Assist, or
- Google One subscription for personal AI features
- CLIProxyAPI server installed and configured
- A web browser for OAuth authentication (or use
-no-browserflag)
Authentication
Start the login process
Run the following command to initiate Gemini OAuth:This will:
- Open your default web browser automatically
- Navigate to Google’s OAuth consent page
- Request permissions for Gemini API access
Complete OAuth authorization
In the browser window:
- Sign in with your Google account
- Review the requested permissions
- Click “Allow” to grant access
- Wait for the callback to complete
Select login mode
After OAuth completes, choose your login mode:Option 1: Code Assist (GCP project, manual selection)
- Select a specific Google Cloud Platform project
- Required for enterprise/team usage
- Allows multiple project activation
- Automatically discovers your Google One project
- Ideal for personal use
- No manual project selection needed
Select GCP project (Code Assist mode only)
If using Code Assist mode, you’ll see a list of available projects:
- Enter a project number (e.g.,
1) - Enter a specific project ID
- Type
ALLto activate all available projects - Press Enter to use the default project
Advanced Options
Specify Project ID at Login
You can specify a project ID directly during login to skip the selection prompt:Manual Browser Authentication
If you’re on a headless server or the browser doesn’t open automatically:Custom OAuth Callback Port
To use a specific port for the OAuth callback server:The default callback port is provider-specific. Use this flag if the default port is already in use.
Activate Multiple Projects
To activate multiple projects in a single login session:- Use the
-loginflag without-project_id - When prompted, type
ALLto activate all available projects - Or specify comma-separated project IDs in your selection
Configuration
Token Storage Location
Authentication tokens are stored in the configured auth directory:- Default location: Set via
-auth-diror in config file - Filename format:
gemini-<email>-<project_id>.json - Example:
[email protected]
Token Contents
The stored token file contains:- OAuth 2.0 access token and refresh token
- Google account email address
- Activated project ID(s)
- Token expiration timestamps
- Auto-discovery settings
Multiple Accounts
You can authenticate with multiple Google accounts:- Run
-loginfor each account - Each account creates a separate token file
- The server automatically manages credential rotation
Verification
To verify your authentication is working:Troubleshooting
Browser doesn’t open automatically
Solution: Use the-no-browser flag and open the URL manually:
“Project selection required” error
Cause: Your account requires an explicit project ID. Solution: Specify a project ID during login:“Cloud AI API is not enabled” error
Cause: Required Google Cloud APIs are not enabled for your project. Solution: The CLI attempts to enable APIs automatically. If it fails:- Visit the Google Cloud Console
- Select your project
- Enable the “Gemini for Google Cloud API” (cloudaicompanion.googleapis.com)
- Run the login command again
OAuth callback timeout
Cause: The OAuth callback server timed out waiting for authorization. Solution:- Complete the OAuth flow more quickly
- Check if your firewall blocks the callback port
- Use
-oauth-callback-portto specify a different port
Token file not created
Cause: Authentication completed but token save failed. Solution:- Verify the auth directory exists and is writable
- Check filesystem permissions
- Review error logs for specific failure reasons
”Backend vs Frontend Project ID” prompt
Cause: Free tier users may receive a different backend project ID. Solution:- Choose Backend (recommended) for access to preview models
- Backend project IDs support gemini-3-* and other preview features
- Frontend IDs may have limited model access
Re-authentication
Tokens are refreshed automatically. To re-authenticate manually:-
Delete the existing token file:
-
Run the login command again: