Skip to main content

Overview

The Gemini provider enables ZeroClaw to use Google’s Gemini models via either API key or OAuth authentication. Provider ID: gemini Aliases: google, google-gemini Public API URL: https://generativelanguage.googleapis.com/v1beta OAuth Internal API URL: https://cloudcode-pa.googleapis.com/v1internal

Authentication

Priority Order

  1. Explicit API key from config
  2. GEMINI_API_KEY environment variable
  3. GOOGLE_API_KEY environment variable
  4. Managed OAuth from auth-profiles.json
  5. Gemini CLI OAuth tokens (~/.gemini/oauth_creds.json)

API Key Authentication

Get an API key from Google AI Studio:

OAuth Authentication (Gemini CLI)

Reuse Gemini CLI credentials:
Credentials are cached in ~/.gemini/oauth_creds.json.

Managed OAuth (Auth Profiles)

Use ZeroClaw’s auth system:

OAuth Project Resolution

For OAuth users, the GCP project is resolved via loadCodeAssist endpoint:
  1. Check GOOGLE_CLOUD_PROJECT or GOOGLE_CLOUD_PROJECT_ID
  2. Call https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist
  3. Extract cloudaicompanionProject from response
  4. Cache for subsequent requests

Configuration

Config File

OAuth Config

Features

Native Tool Calling

Supported: No Gemini does not support native tool calling in the current implementation. Tool requests will fail.

Vision Support

Supported: Yes Images are sent as inline data with base64 encoding:
Image markers in user messages:

Thinking Models

Supported: Yes Thinking models (e.g., gemini-3-pro-preview) mark reasoning parts with thought: true:
ZeroClaw automatically filters thinking parts and returns only the final answer.

Token Usage Tracking

Supported: Yes Usage data is extracted from response:

API Endpoints

Generate Content (API Key)

Endpoint: POST /v1beta/models/{model}:generateContent?key={api_key} Request:
Response:

Generate Content (OAuth)

Endpoint: POST https://cloudcode-pa.googleapis.com/v1internal:generateContent Authorization: Bearer <oauth_token> Request:
Response: Same format as API key, nested under response field.

Request Configuration

Max Tokens

Default: 8192 Fixed in the provider implementation.

Temperature

Range: 0.0 - 2.0 Default: 0.7 (from config)

Timeouts

  • Request timeout: 120 seconds
  • Connection timeout: 10 seconds

Message Format

System Instruction

Sent as top-level systemInstruction:
Multiple system messages are merged with \n\n.

User Messages

Simple text:
With images:

Assistant Messages

Gemini uses model role instead of assistant:

OAuth Token Refresh

Gemini CLI OAuth tokens are automatically refreshed when:
  1. Token expiry is unknown
  2. Token is already expired
  3. Token will expire within 60 seconds
Refresh endpoint: https://oauth2.googleapis.com/token Refresh request:

OAuth Credential Rotation

Multiple OAuth credential files are supported:
  • ~/.gemini/oauth_creds.json (primary)
  • ~/.gemini-*-home/.gemini/oauth_creds.json (additional)
On rate limit or server errors, the provider automatically rotates to the next credential.

Stop Reasons

Normalized stop reasons:

Error Handling

Authentication Errors

OAuth Errors

For rate limits or service errors, the provider automatically:
  1. Rotates to next OAuth credential (if available)
  2. Refreshes the token
  3. Retries the request

Generation Config Errors

Some OAuth endpoints reject generationConfig. The provider automatically retries without it:

Provider Capabilities

Warmup

Supported: Yes For API key users, warmup calls the /models endpoint:
For OAuth users, warmup verifies and refreshes the token without making a full request.

Example Usage

API Key

OAuth (Gemini CLI)

With Vision

Thinking Model

Authentication Source Diagnostics

Check which credential source is active:
Returns:
  • "config" - Explicit API key from config
  • "GEMINI_API_KEY env var" - From env var
  • "GOOGLE_API_KEY env var" - From env var
  • "Gemini CLI OAuth" - From ~/.gemini/oauth_creds.json
  • "auth-profiles" - Managed OAuth
  • "none" - No credentials

Limitations

  • No native tool calling support
  • OAuth requires GCP project resolution
  • OAuth users must use internal Code Assist API
  • Generation config may not work with some OAuth endpoints
  • Thinking parts are automatically filtered (not exposed)