opencode-gemini-cli-oauth
v1.3.0
Published
OpenCode plugin for Gemini CLI OAuth authentication - use Google account quota without API keys
Maintainers
Readme
OpenCode Gemini CLI OAuth Plugin
Use 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.
✨ Features
- 🔐 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-authplugin - 🆓 Free Quota - Use Google's free tier quota (1,500 requests/day per account)
📦 Installation
Prerequisites
Gemini CLI must be installed and authenticated:
npm install -g @google/gemini-cli gemini auth login # Authenticate with your Google accountOpenCode v1.0.0 or higher
Install Plugin
# Install globally from NPM
npm install -g opencode-gemini-cli-oauth⚡ Easy Setup (Recommended)
Run the setup wizard to automatically configure OpenCode with Gemini models:
opencode-gemini-setupThis will:
- Check your Gemini CLI authentication
- Login if needed
- Configure
opencode.jsonwith the latest models (Gemini 2.0, 1.5, etc.)
Manual Configuration
If you prefer to configure manually, add to ~/.config/opencode/opencode.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"] }
}
}
}
}
}🚀 Usage
1. Authenticate with Gemini CLI
# Login with your Google account
gemini auth login
# Verify authentication
gemini "hello"2. Launch OpenCode
opencode3. Select Model
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:
Authenticate each account with Gemini CLI:
gemini auth login # Login with account 1 # Complete OAuth flow # Repeat for more accounts (Gemini CLI will store them)Plugin automatically rotates between accounts when:
- An account hits rate limit (429 error)
- Distributing requests evenly
Check account pool:
cat ~/.gemini/opencode-plugin/account_pool.json
🔧 How It Works
OAuth Token Injection
- Plugin reads credentials from
~/.gemini/oauth_creds.json(created by Gemini CLI) - Injects
Authorization: Bearer <access_token>header to Gemini API requests - Removes
?key=parameter from URLs (OAuth doesn't need it)
- Plugin reads credentials from
Request Interception
- Only intercepts requests to
generativelanguage.googleapis.com - Other providers (Antigravity, standard Google) are unaffected
- Only intercepts requests to
Token Refresh
- Monitors token expiry (
expiry_datefield) - Auto-refreshes 5 minutes before expiration
- Uses
refresh_tokento get newaccess_token
- Monitors token expiry (
Rate Limit Handling
- Detects 429 responses
- Marks account as rate-limited with
retry-aftertimestamp - 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
"No OAuth credentials found"
# Re-authenticate with Gemini CLI
gemini auth login"Failed to refresh access token"
# Clear cached credentials and re-auth
rm ~/.gemini/oauth_creds.json
gemini auth loginPlugin not loading
# Check plugin is installed
npm list -g opencode-gemini-cli-oauth
# Re-link if needed
cd ~/projects/opencode-gemini-cli-oauth
npm linkRate limited on all accounts
# Check account pool status
cat ~/.gemini/opencode-plugin/account_pool.json
# Clear rate limit timestamps
echo '{"accounts":[],"currentIndex":0}' > ~/.gemini/opencode-plugin/account_pool.json
# Or wait for retry-after period to expire🔒 Security Notes
- OAuth credentials are stored locally in
~/.gemini/oauth_creds.json - Client ID/Secret are public (safe for "installed applications" per Google OAuth guidelines)
- Tokens auto-refresh - no manual intervention needed
- No credentials sent to third parties - direct Google API communication only
📚 API Reference
Exported Classes
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 }🤝 Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Submit a pull request
📄 License
MIT License - see LICENSE file for details
🙏 Credits
- Built by @yusuf
- Inspired by opencode-antigravity-auth
- Uses Google Auth Library
🔗 Related Projects
- Gemini CLI - Official Google Gemini CLI
- OpenCode - AI-powered code editor
- OpenCode Antigravity Auth - Antigravity integration
Made with ❤️ for the OpenCode community
