npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

opencode-gemini-cli-oauth

v1.3.0

Published

OpenCode plugin for Gemini CLI OAuth authentication - use Google account quota without API keys

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-auth plugin
  • 🆓 Free Quota - Use Google's free tier quota (1,500 requests/day per account)

📦 Installation

Prerequisites

  1. Gemini CLI must be installed and authenticated:

    npm install -g @google/gemini-cli
    gemini auth login  # Authenticate with your Google account
  2. OpenCode 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-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.)

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

opencode

3. 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:

  1. 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)
  2. Plugin automatically rotates between accounts when:

    • An account hits rate limit (429 error)
    • Distributing requests evenly
  3. Check account pool:

    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 <access_token> 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 unaffected
  3. Token Refresh

    • Monitors token expiry (expiry_date field)
    • Auto-refreshes 5 minutes before expiration
    • Uses refresh_token to get new access_token
  4. 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

"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 login

Plugin not loading

# Check plugin is installed
npm list -g opencode-gemini-cli-oauth

# Re-link if needed
cd ~/projects/opencode-gemini-cli-oauth
npm link

Rate 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

  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

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:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

📄 License

MIT License - see LICENSE file for details

🙏 Credits

🔗 Related Projects


Made with ❤️ for the OpenCode community