opencode-gemini-auth

repository·main·Indexed 22 days ago

https://github.com/jenslys/opencode-gemini-auth

A Gemini OAuth plugin for the Opencode CLI (version 1.4.16) that enables authentication via Google accounts. It allows users to utilize existing Gemini plans, quotas, and Gemini Code Assist subscriptions (Standard or Enterprise) within Opencode. The plugin supports Google Cloud projectId configuration, proxy settings, model whitelisting/blacklisting, and 'thinking' feature configurations for Gemini 2.5 and 3 models.

Tokens
3.7K
Snippets
9
Records
31
Agent score
79%

What's inside opencode-gemini-auth

  1. Configure Gemini 'Thinking' features

    main

    You can enable "thinking" features per-model using thinkingConfig within provider.google.models. The available fields depend on the model family:

    • Gemini 3 models: Use thinkingLevel with values "low" or "high".
    • Gemini 2.5 models: Use thinkingBudget (a token count).
    • includeThoughts (boolean): Controls whether the model emits internal thoughts.

    Example configuration:

    {
      "provider": {
        "google": {
          "models": {
            "gemini-3-pro-preview": {
              "options": {
                "thinkingConfig": {
                  "thinkingLevel": "high",
                  "includeThoughts": true
                }
              }
            },
            "gemini-2.5-flash": {
              "options": {
                "thinkingConfig": {
                  "thinkingBudget": 8192,
                  "includeThoughts": true
                }
              }
            }
          }
        }
      }
    }
  2. Install the Gemini OAuth plugin for Opencode

    main

    To use your Google account's Gemini plan and quotas within Opencode, add the plugin to your Opencode configuration file (typically ~/.config/opencode/opencode.json).

    Note: If you are using an organization-backed Gemini Code Assist subscription (Standard or Enterprise), you must explicitly configure a Google Cloud projectId.

    {
      "$schema": "https://opencode.ai/config.json",
      "plugin": ["opencode-gemini-auth@latest"]
    }
  3. Update the Gemini plugin

    main

    Opencode does not automatically update plugins. To update to the latest version, you must manually clear the cached plugin files and then run Opencode to trigger a fresh installation.

    # Clear the specific plugin cache
    rm -rf ~/.cache/opencode/node_modules/opencode-gemini-auth
    
    # Run Opencode to trigger a fresh install
    opencode
  4. Authenticate Opencode with Google OAuth

    main

    Follow these steps to link your Google account to the Opencode CLI:

    1. Run the login command:
      opencode auth login
    2. Select Google from the provider list.
    3. Select OAuth with Google (Gemini CLI).
    4. Approve access in the browser window that opens.

    If the local callback server fails (e.g., due to a port conflict or a headless environment), you can manually paste the callback URL or the authorization code when prompted.

    opencode auth login
  5. Manage the Gemini model list (Whitelist/Blacklist)

    main

    You can control which models appear in the Opencode picker using whitelist or blacklist settings under provider.google. Use exact model IDs (verifiable via opencode models google).

    • whitelist: Only show the listed model IDs.
    • blacklist: Hide specific model IDs from the default list.
    {
      "provider": {
        "google": {
          "whitelist": [
            "gemini-2.5-flash",
            "gemini-2.5-pro",
            "gemini-3-flash-preview",
            "gemini-3-pro-preview"
          ]
        }
      }
    }
  6. Configure Proxy for Gemini requests

    main

    If your network requires an HTTP proxy for Google API calls, set the OPENCODE_GEMINI_AUTH_PROXY environment variable before starting Opencode. This applies to OAuth, token refresh, project/quota lookup, and Gemini request forwarding.

    OPENCODE_GEMINI_AUTH_PROXY=http://127.0.0.1:8080 opencode
  7. Configure the Google Cloud Project ID

    main

    By default, the plugin attempts to find a suitable project. To force a specific project (required for Standard/Enterprise subscriptions or Workspace accounts), use one of the following methods:

    1. Opencode Config File: Set projectId under provider.google.options in ~/.config/opencode/opencode.json.

    2. Environment Variables: Set OPENCODE_GEMINI_PROJECT_ID, GOOGLE_CLOUD_PROJECT, or GOOGLE_CLOUD_PROJECT_ID.

    {
      "provider": {
        "google": {
          "options": {
            "projectId": "your-specific-project-id"
          }
        }
      }
    }
  8. Troubleshoot 429 Quota Errors

    main

    If you encounter 429 RESOURCE_EXHAUSTED or QUOTA_EXHAUSTED errors, consider the following:

    • Missing Project ID: Without a configured projectId, the plugin uses a managed free-tier project with lower quotas.
    • Model Limits: Quotas are tracked per model (e.g., gemini-3-pro-preview has different limits than gemini-3-flash-preview).
    • Large Prompts: OAuth/Code Assist does not support cached content; long system prompts and history consume quota quickly.
    • Parallel Sessions: Multiple Opencode windows share the same quota bucket.
    • Subscription Type: If using Gemini Code Assist Standard or Enterprise, ensure provider.google.options.projectId is set.
  9. Debug Gemini requests

    main

    To view detailed logs of Gemini requests and responses, set the OPENCODE_GEMINI_DEBUG environment variable to 1. This will generate gemini-debug-<timestamp>.log files in your working directory containing sanitized request/response details.

    OPENCODE_GEMINI_DEBUG=1 opencode
  10. Configure Thinking capabilities for Gemini models

    main

    When interacting with Gemini models that support reasoning, you can provide a ThinkingConfig object. The configuration keys vary depending on the model version:

    • Gemini 3 models: Use thinkingLevel with values 'low', 'medium', or 'high'.
    • Gemini 2.5 models: Use thinkingBudget (a number).

    You can also use includeThoughts (boolean) to control whether the model's reasoning process is returned in the response.