Skip to main content

Gemini Provider

Access Google Gemini models via OAuth authentication with automatic token management and interactive model configuration.

Quick Start

Authentication

Initial Setup

1

First Run

Run ccs gemini "your prompt" - browser opens automatically
2

Google OAuth

Sign in with your Google account
3

Token Cached

OAuth token saved to ~/.ccs/cliproxy/auth/gemini-{email}.json
4

Auto Refresh

Token refresh is handled automatically by CLIProxy

OAuth Flow Specifics

Authorization Code Flow:
  • Callback server spawns on provider-specific port
  • Browser opens for Google OAuth consent
  • Token received via HTTP callback
  • Runtime-managed refresh prevents mid-request failures
Automatic Token Refresh:
  • refresh ownership is delegated upstream to CLIProxy
  • CCS verifies that local auth material still exists
  • prevents common mid-session auth failures without requiring manual refresh in normal flows
  • prompts for re-auth if upstream refresh can no longer recover the session

Headless Authentication

For servers without browser access:
Complete OAuth on another device - CCS detects when token is cached.

Multi-Account Support

Manage multiple Google accounts seamlessly:
Account Registry: ~/.ccs/cliproxy/accounts.json

Real-Time Quota Display

CCS displays real-time quota information for Gemini accounts via Dashboard and CLI.

Dashboard Display

Location: Dashboard → OAuth Providers → Gemini Displays:
  • Requests per minute (RPM) usage
  • Tokens per minute (TPM) usage
  • Requests per day (RPD) usage
  • Limit reset times
Backend Caching:
  • Quota data cached for 2 minutes to reduce API load
  • Automatic re-authentication if token expired
  • Dashboard shows cached timestamp

CLI Quota Check

Features:
  • Displays all authenticated Gemini accounts
  • Shows cached timestamp (2-minute cache)
  • Proactive token refresh (5 minutes before expiry)
Quota Response Caching: CCS caches quota responses to prevent excessive API calls: Cache Location: In-memory (not persisted to disk)

Tool Name Sanitization

Gemini enforces a 64-character limit on tool names. CCS automatically handles this via ToolSanitizationProxy.

The Problem

Claude MCP tools can have names exceeding 64 characters:
Gemini API Error: “Invalid tool name: must be 64 characters or fewer”

How CCS Fixes It

ToolSanitizationProxy intercepts requests and:
  1. Detects tool names exceeding 64 characters
  2. Creates short hashes using <prefix>_<6-char-md5> format (e.g., mcp__long-server__toolNamemcp___a1b2c3)
  3. Maintains bidirectional mapping
  4. Restores original names in responses

Architecture

Proxy Lifecycle:
  • Spawned automatically when using Gemini provider
  • Runs on random port (127.0.0.1)
  • Shuts down with Claude session

Sanitization Process

Request Flow:
Response Flow:

Debug Mode

Enable verbose logging to see sanitization activity:
Log Location: ~/.ccs/logs/tool-sanitization-proxy.log

When Sanitization Happens

Automatically enabled for:
  • All CLIProxy providers (gemini, codex, antigravity)
  • Any provider configured via config.cliproxy
Why all providers?
  • ToolSanitizationProxy runs for all CLIProxy-based providers to ensure compatibility across different model APIs

Configuration

Sanitization is automatic and requires no configuration. To disable warnings:

Performance Impact

Minimal overhead:
  • Hash generation: under 1ms per tool
  • Request/response transformation: under 5ms
  • In-memory mapping (no disk I/O)
Timeout: 120 seconds (configurable via timeoutMs)

Model Configuration

Interactive Model Picker

Select Gemini model interactively with --config flag:
First-Run Detection: If no model configured, prompts automatically before first execution.

Available Models

Gemini 3 Pro requires a paid Google account. Use Gemini 2.5 Pro for free tier.

Model Settings Storage

Settings saved to ~/.ccs/gemini.settings.json:
Priority: Custom settings → User overrides → Bundled defaults

Configuration

Config Keys

Configure via ~/.ccs/config.yaml:

Environment Variables

These are set automatically by CCS. Manual override rarely needed.

Commands Reference

Basic Usage

Authentication Commands

Account Management

Configuration

Troubleshooting

Token Refresh Failures

Symptom: UND_ERR_SOCKET errors during execution Cause: Token expired mid-request Solution: Proactive refresh handles this automatically. If issue persists:

Model Not Working

Symptom: API errors, tool call failures Cause: Model incompatible with Claude Code Solution: Change model via --config:
Gemini 3 Pro (Preview) has known issues with tool calls. Use “High” variant instead.

Multiple Accounts Confusion

Symptom: Wrong account being used Solution: Check default account:

Browser Doesn’t Open

Symptom: OAuth flow stuck waiting for browser Solution: Use headless mode:

Storage Locations

Cost Information

Quota Management: Automatic rotation if rate limited (config: quota-exceeded.switch-project: true)

Advanced Features

Token Structure

OAuth token file format (gemini-{email}.json):

Proactive Refresh Logic

  1. Before execution: Check expiry_date
  2. If < 5 minutes until expiry: Trigger refresh
  3. If refresh succeeds: Update token file
  4. If refresh fails: Prompt re-auth
  5. Execute Claude CLI with valid token
Why 5 minutes? Matches CLIProxyAPI behavior, prevents race conditions during long API calls.

Next Steps

Multi-Account Setup

Configure multiple Google accounts

Model Selection

Choose optimal Gemini model

Remote Proxy

Connect to external CLIProxy server

WebSearch Integration

Enable Gemini-powered web search