Connect OpenClaw to Google Gemini — 1M Token Context + Free Tier
Connect OpenClaw to Google Gemini
Section titled “Connect OpenClaw to Google Gemini”Let me tell you about the best-kept secret in AI: Google Gemini’s free tier is absurdly generous.
While Claude and GPT charge by the token, Gemini gives you 1 million tokens of context and a solid free tier. If you’re building something that needs to process long documents or maintain extensive conversation history, Gemini is hard to beat.
Here’s how to set it up with OpenClaw.
Why Gemini?
Section titled “Why Gemini?”| Feature | Gemini | Claude | GPT-4 |
|---|---|---|---|
| Free Tier | ✅ Yes | ❌ No | ❌ No |
| Context Window | 1M tokens | 200K tokens | 128K tokens |
| Multimodal | ✅ Images, audio, video | ✅ Images | ✅ Images |
| Speed | Fast | Medium | Medium |
Quick Start (5 Minutes)
Section titled “Quick Start (5 Minutes)”Step 1: Get Your API Key
Section titled “Step 1: Get Your API Key”- Go to Google AI Studio
- Sign in with your Google account
- Click “Get API Key” → “Create API Key”
- Copy the key
Step 2: Configure OpenClaw
Section titled “Step 2: Configure OpenClaw”Option A: Environment Variable
export GEMINI_API_KEY="your-api-key-here"Option B: CLI Configuration
openclaw config set models.providers.gemini.apiKey "your-api-key-here"Step 3: Set Gemini as Your Model
Section titled “Step 3: Set Gemini as Your Model”Edit your OpenClaw config:
{ agents: { defaults: { model: { primary: "gemini/gemini-2.5-flash" } } }}That’s it. You’re now using Gemini.
OAuth Authentication (Alternative)
Section titled “OAuth Authentication (Alternative)”For more secure, key-free authentication via your Google account:
Option 1: During Onboarding Wizard
- Run
openclaw onboard - Select “Google” as your AI provider
- Choose “OAuth Authentication”
- Complete the Google sign-in flow in your browser
- OpenClaw stores your auth token securely
Option 2: CLI Plugin Authentication
If you’ve already installed OpenClaw, enable the Gemini CLI auth plugin:
# Enable the Gemini CLI auth pluginopenclaw plugins enable google-gemini-cli-auth
# Authenticate and set as default provideropenclaw models auth login --provider google-gemini-cli --set-defaultThis opens a browser window for Google OAuth. Once authenticated, you can use Gemini without managing API keys.
Note: OAuth is great for personal use. For automation or server deployments, use an API key instead.
Available Gemini Models
Section titled “Available Gemini Models”| Model | Best For | Context Window |
|---|---|---|
| gemini-2.5-flash | Fast responses | 1M tokens |
| gemini-2.5-pro | Complex reasoning | 1M tokens |
| gemini-2.0-flash | Balanced | 128K tokens |
Model Selection
Section titled “Model Selection”{ agents: { defaults: { model: { primary: "gemini/gemini-2.5-flash", fallback: ["gemini/gemini-2.0-flash"] } } }}Understanding Gemini’s Free Tier
Section titled “Understanding Gemini’s Free Tier”Google’s free tier includes:
- 60 requests per minute (Flash models)
- 2 requests per minute (Pro models)
- 1 million token context window
For most personal use cases, the free tier is more than enough.
Rate Limits
Section titled “Rate Limits”If you hit rate limits, consider:
- Switching to Flash models for higher limits
- Adding delays between requests
- Upgrading to Gemini API paid plan
Advanced Configuration
Section titled “Advanced Configuration”Full Provider Setup
Section titled “Full Provider Setup”{ models: { providers: { gemini: { apiKey: "your-api-key", models: [ { id: "gemini-2.5-flash", name: "Gemini 2.5 Flash", reasoning: false, input: ["text", "image"], contextWindow: 1000000, maxTokens: 8192 } ] } } }}Using with Other Providers
Section titled “Using with Other Providers”Mix Gemini with other models:
{ agents: { defaults: { model: { primary: "gemini/gemini-2.5-flash", // Fast, free fallback: ["anthropic/claude-sonnet-4"] // For complex tasks } } }}Troubleshooting
Section titled “Troubleshooting””API key not valid”
Section titled “”API key not valid””Double-check your API key:
- Go to Google AI Studio
- Verify the key is active
- Ensure no extra whitespace when copying
”Quota exceeded”
Section titled “”Quota exceeded””You’ve hit the free tier limit. Options:
- Wait for the quota to reset (daily)
- Switch to Flash models for higher limits
- Upgrade to a paid plan
”Model not found”
Section titled “”Model not found””Verify the model ID:
openclaw models listMake sure you’re using the correct format: gemini/model-name
Still stuck? Our AI Setup Assistant is trained on all OpenClaw documentation and can help troubleshoot your Gemini setup in real-time.
Gemini vs Other Providers
Section titled “Gemini vs Other Providers”| Aspect | Gemini | Claude | OpenAI |
|---|---|---|---|
| Best For | Long docs, multimodal | Creative, nuanced | Coding, analysis |
| Free Tier | ✅ Generous | ❌ None | ❌ None |
| Context | 1M tokens | 200K tokens | 128K tokens |
| Coding | Good | Excellent | Excellent |
My recommendation: Use Gemini for document processing and as a cost-effective fallback. Keep Claude or GPT for tasks requiring the best quality output.
What’s Next?
Section titled “What’s Next?”- Install OpenClaw → — Full setup guide
- Use Ollama → — Free local AI
- Connect Telegram → — Control from your phone
- Docker deployment → — 24/7 availability
Need help? Join the OpenClaw Discord or check the official docs.
OpenClaw Expert
Still stuck?
If this page didn't answer your case, ask OpenClaw Expert for step-by-step guidance.