OpenCode plugin for Gemini CLI OAuth authentication - use Google account quota without API keys
npm install opencode-gemini-cli-oauthUse Gemini models in OpenCode with your Google account quota - no API keys needed!
This plugin integrates Gemini CLI's OAuth authentication with OpenCode, allowing you to use Google's free Gemini quota without generating API keys.
- 🔐 OAuth Authentication - Reuses Gemini CLI credentials from ~/.gemini/oauth_creds.json
- 👥 Multi-Account Support - Automatic rotation across multiple Google accounts
- 🔄 Auto Token Refresh - Handles expired tokens seamlessly
- 🚦 Rate Limit Handling - Auto-switches to next account when rate limited
- 🤝 Antigravity Compatible - Works alongside opencode-antigravity-auth plugin
- 🆓 Free Quota - Use Google's free tier quota (1,500 requests/day per account)
1. Gemini CLI must be installed and authenticated:
``bash`
npm install -g @google/gemini-cli
gemini auth login # Authenticate with your Google account
2. OpenCode v1.0.0 or higher
`bash`Install globally from NPM
npm install -g opencode-gemini-cli-oauth
Run the setup wizard to automatically configure OpenCode with Gemini models:
`bash`
opencode-gemini-setup
This will:
1. Check your Gemini CLI authentication
2. Login if needed
3. Configure opencode.json with the latest models (Gemini 2.0, 1.5, etc.)
If you prefer to configure manually, add to ~/.config/opencode/opencode.json:
`json`
{
"plugin": [
"opencode-antigravity-auth@beta",
"opencode-gemini-cli-oauth"
],
"provider": {
"gemini-cli-oauth": {
"npm": "@ai-sdk/google",
"models": {
"gemini-2.5-flash-exp": {
"name": "Gemini 2.5 Flash (Google Account)",
"limit": { "context": 1048576, "output": 65536 },
"modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
}
}
}
}
}
`bashLogin with your Google account
gemini auth login
$3
`bash
opencode
`$3
In OpenCode:
- Press
Ctrl+P → "Switch Model"
- Choose "Gemini 2.5 Flash (Google Account)" or any model with "(Google Account)"
- Start chatting!🔀 3-Way Authentication Options
After installing this plugin, you have 3 authentication methods for Google models:
| Method | Provider | Models | Source | Quota |
|--------|----------|--------|--------|-------|
| 1. Google Account (OAuth) |
gemini-cli-oauth | Gemini 2.5 Flash/Pro, Gemini 2.0 Flash | This plugin | Google account free tier |
| 2. API Key | google-api-key | Gemini 1.5/2.5 models | Generated from AI Studio | API key quota |
| 3. Antigravity | google | Gemini 3 Pro/Flash, Claude Sonnet/Opus | opencode-antigravity-auth | Antigravity quota |All three can coexist without conflicts!
👥 Multi-Account Setup
To rotate across multiple Google accounts:
1. Authenticate each account with Gemini CLI:
`bash
gemini auth login # Login with account 1
# Complete OAuth flow # Repeat for more accounts (Gemini CLI will store them)
`2. Plugin automatically rotates between accounts when:
- An account hits rate limit (429 error)
- Distributing requests evenly
3. Check account pool:
`bash
cat ~/.gemini/opencode-plugin/account_pool.json
`🔧 How It Works
1. OAuth Token Injection
- Plugin reads credentials from
~/.gemini/oauth_creds.json (created by Gemini CLI)
- Injects Authorization: Bearer header to Gemini API requests
- Removes ?key= parameter from URLs (OAuth doesn't need it)2. Request Interception
- Only intercepts requests to
generativelanguage.googleapis.com
- Other providers (Antigravity, standard Google) are unaffected3. Token Refresh
- Monitors token expiry (
expiry_date field)
- Auto-refreshes 5 minutes before expiration
- Uses refresh_token to get new access_token4. Rate Limit Handling
- Detects 429 responses
- Marks account as rate-limited with
retry-after timestamp
- Switches to next available account
- Retries request automatically📊 Quota Management
Free Tier Limits (per Google account):
- Requests: 1,500 requests/day
- Tokens: 1,000,000 tokens/day
- RPM: 15 requests/minute (Gemini 2.5 Flash)
With 5 accounts, you get:
- 7,500 requests/day
- 5,000,000 tokens/day
- Automatic rotation on rate limits
🐛 Troubleshooting
$3
`bash
Re-authenticate with Gemini CLI
gemini auth login
`$3
`bash
Clear cached credentials and re-auth
rm ~/.gemini/oauth_creds.json
gemini auth login
`$3
`bash
Check plugin is installed
npm list -g opencode-gemini-cli-oauthRe-link if needed
cd ~/projects/opencode-gemini-cli-oauth
npm link
`$3
`bash
Check account pool status
cat ~/.gemini/opencode-plugin/account_pool.jsonClear rate limit timestamps
echo '{"accounts":[],"currentIndex":0}' > ~/.gemini/opencode-plugin/account_pool.jsonOr wait for retry-after period to expire
`🔒 Security Notes
1. OAuth credentials are stored locally in
~/.gemini/oauth_creds.json
2. Client ID/Secret are public (safe for "installed applications" per Google OAuth guidelines)
3. Tokens auto-refresh - no manual intervention needed
4. No credentials sent to third parties - direct Google API communication only📚 API Reference
$3
`typescript
import {
OAuthManager, // OAuth token management
AccountManager, // Multi-account rotation
StorageManager, // Credentials storage
} from 'opencode-gemini-cli-oauth';// Example: Get current access token
const oauthManager = new OAuthManager();
const token = await oauthManager.getAccessToken();
// Example: Check account pool stats
const accountManager = new AccountManager();
const stats = await accountManager.getPoolStats();
console.log(stats); // { totalAccounts: 5, availableAccounts: 4, rateLimitedAccounts: 1 }
``Contributions welcome! Please:
1. Fork the repository
2. Create a feature branch
3. Submit a pull request
MIT License - see LICENSE file for details
- Built by @yusuf
- Inspired by opencode-antigravity-auth
- Uses Google Auth Library
- Gemini CLI - Official Google Gemini CLI
- OpenCode - AI-powered code editor
- OpenCode Antigravity Auth - Antigravity integration
---
Made with ❤️ for the OpenCode community