Skip to main content
The Gemini provider supports all Google Gemini models including Gemini 2.0, 1.5 Pro, Flash, and vision capabilities.

Configuration

string
required
Set to "gemini" or "google" or "google-gemini"
string
Google API key. Get yours at aistudio.google.com/apikey
string
required
Model name: gemini-2.0-flash, gemini-1.5-pro, etc.
number
Sampling temperature (0.0-2.0). Defaults to 0.7.
number
Maximum output tokens (called maxOutputTokens in Gemini API). Defaults to 8192.

Example Configuration

Authentication Methods

The Gemini provider supports three authentication methods (in priority order):

1. Explicit API Key (Config)

2. Environment Variables

3. Gemini CLI OAuth Token

Reuse existing Gemini CLI credentials from ~/.gemini/oauth_creds.json:
The provider automatically:
  • Detects and loads the token
  • Checks expiration (5-minute safety buffer)
  • Refreshes expired tokens using the refresh token
  • Persists refreshed tokens back to ~/.gemini/oauth_creds.json
No configuration needed — just run gemini auth login and NullClaw will use those credentials.

Supported Models

  • Gemini 2.0: gemini-2.0-flash, gemini-2.0-flash-exp
  • Gemini 1.5: gemini-1.5-pro, gemini-1.5-flash, gemini-1.5-flash-8b
  • Legacy: gemini-pro, gemini-pro-vision
Model names can optionally include models/ prefix:
  • gemini-2.0-flash → auto-expanded to models/gemini-2.0-flash
  • models/gemini-1.5-pro → used as-is

Capabilities

Message Format

Gemini uses a different message format:
  • Roles are user and model (not assistant)
  • System messages go in top-level system_instruction field
  • Content is structured as parts array

Vision Support

Gemini supports multimodal input (text + images):
Note: Gemini only supports base64-encoded images via inlineData. Image URLs are converted to text references: [Image: https://example.com/photo.jpg].

Streaming

Gemini uses Server-Sent Events (SSE) for streaming: Endpoint:
Response Format:
The provider automatically:
  • Parses SSE lines
  • Extracts candidates[0].content.parts[0].text
  • Calls streaming callback for each delta
  • Accumulates full response

OAuth Token Refresh

When using Gemini CLI credentials, the provider handles token refresh automatically:
Refresh happens automatically when:
  • Token is within 5 minutes of expiration
  • refresh_token is available
Refreshed tokens are persisted to ~/.gemini/oauth_creds.json.

Code Example

From src/providers/gemini.zig:

Error Handling

The provider classifies common Gemini API errors:
  • error.RateLimited — 429 rate limit exceeded
  • error.InvalidApiKey — Authentication failed
  • error.ApiError — Generic API error
  • error.NoResponseContent — Empty response
  • error.RefreshFailed — OAuth token refresh failed