Skip to content

Comments

Added Gemini quota tool#35

Closed
ineersa wants to merge 3 commits intojenslys:mainfrom
ineersa:quota-tool
Closed

Added Gemini quota tool#35
ineersa wants to merge 3 commits intojenslys:mainfrom
ineersa:quota-tool

Conversation

@ineersa
Copy link

@ineersa ineersa commented Jan 14, 2026

Code written by Gemini 3 Pro.

This adds actual user quota check as separate tool, I couldn't think of anything better as not familiar with opencode and plugins.

image

Summary of Changes:

  1. State Management (src/plugin/state.ts): Created a helper module to store and retrieve the plugin's global state (GetAuth, Provider, PluginClient), allowing tools to access authentication context.
  2. Type Definitions (src/plugin/types.ts):
    • Added QuotaBucket and RetrieveUserQuotaResponse interfaces to model the API response.
    • Updated PluginResult to include the tool property for registering custom tools.
  3. Tool Implementation (src/plugin/tools.ts): Implemented the gemini-quota tool. It handles:
    • retrieving the current OAuth token.
    • Refreshing the token if expired.
    • resolving the active Google Cloud project ID.
    • Calling the v1internal:retrieveUserQuota endpoint.
  4. Plugin Registration (src/plugin.ts): Updated GeminiCLIOAuthPlugin to:
    • Initialize the global state on load.
    • Register and expose the gemini-quota tool.

@jenslys
Copy link
Owner

jenslys commented Jan 31, 2026

Not sure if this is possible yet, but would it be more beneficial to have this as a custom command instead of doing two or more LLM calls to fetch the quota?

@ineersa
Copy link
Author

ineersa commented Feb 5, 2026

Not sure if this is possible yet, but would it be more beneficial to have this as a custom command instead of doing two or more LLM calls to fetch the quota?

Yeah, that would be great. Maybe you could extract quota check from here.

Command was my first idea, I tried but it wasn't working, then I tried to hookup to /status in opencode, didn't work too, so just made it a tool.

Sorry, I'm not typescript developer and not very familiar with opencode plugin system, was just going via docs.

@ineersa
Copy link
Author

ineersa commented Feb 11, 2026

Okay so I was checking https://github.com/vbgate/opencode-mystatus/blob/main/plugin/mystatus.ts and this one works pretty much same way.

To add command need to add to opencode settings something like this:

"gemini-quota": {
      "description": "Query quota usage for Gemini account",
      "template": "Use the gemini-quota tool to query quota usage. Format in markdown table view, remainingFraction is percentage."
    },

In theory we can pre format it as they do in /mystatus and say that it should output it as is, but it looks like it still uses LLM to actually output it.

@jenslys
Copy link
Owner

jenslys commented Feb 21, 2026

This is now available in the latest release https://github.com/jenslys/opencode-gemini-auth/releases/tag/v1.4.0

@jenslys jenslys closed this Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants