Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@patelhiren
Copy link
Contributor

Intent

Enable usage tracking for the google-antigravity provider so users can monitor their quota consumption and remaining credits in the /status output, similar to existing providers (Claude, Copilot, etc.).

Problem: Users running Clawdbot with Google Antigravity have no visibility into their credit usage or per-model quota limits.

Solution: Add dedicated fetcher that queries Google Cloud Code API to display:

  • Overall credit usage (available/monthly)
  • Per-model quota information with reset times
  • Individual model IDs sorted by highest usage

User Impact: Users can now see quota information like:

📊 Usage: Credits 75% | gemini-pro-1.5 40% (resets 4h 59m) | gemini-flash-2.0 20% (resets 4h 59m)

Implementation

API Integration:

  • Fetches from two Google Cloud Code API endpoints:
    • loadCodeAssist - retrieves credits and plan information
    • fetchAvailableModels - retrieves per-model quota data
  • Extracts project ID from first endpoint and chains it to the second for proper authorization
  • Includes required metadata and headers per API specification

Data Processing:

  • Parses credits (available/monthly) and plan info (tier name or plan type)
  • Extracts per-model quotas with remaining fractions and reset times
  • Reports individual model IDs (e.g., gemini-pro-1.5, gemini-flash-2.0) rather than grouping by families
  • Sorts models by usage (highest first) and displays top 10
  • Skips internal models (containing chat_ or tab_)

Error Handling:

  • Graceful degradation: works if either endpoint fails
  • Returns "Token expired" on 401 and stops early
  • Only reports error if both endpoints fail and no data available

Debug Logging:

  • Comprehensive logging at each stage with [antigravity] prefix
  • Logs credits, extracted model quotas, built windows, and final snapshot
  • Visible when logging.level: "debug" is set in config

Testing

14 comprehensive test cases covering:

  • Both endpoints succeed/fail independently
  • Plan info extraction and fallback logic
  • Reset time parsing and edge cases
  • String number parsing
  • Model sorting and limiting
  • Network errors with graceful degradation
  • Token expiration handling

Files Changed

  • src/infra/provider-usage.fetch.antigravity.ts (new, 272 lines)
  • src/infra/provider-usage.fetch.antigravity.test.ts (new, 467 lines, 14 tests)
  • src/infra/provider-usage.fetch.ts (export added)
  • src/infra/provider-usage.load.ts (case added for google-antigravity)

Reference

Implementation based on: https://github.com/skainguyen1412/antigravity-usage

Test Plan

# Run tests
pnpm test provider-usage.fetch.antigravity

# Build
pnpm build

# Enable debug logging to see usage data
# Edit ~/.clawdbot/config.json:
{
  "logging": {
    "level": "debug"
  }
}

# View logs
tail -f /tmp/clawdbot/clawdbot-$(date +%Y-%m-%d).log | grep antigravity

@patelhiren
Copy link
Contributor Author

Adapted most of the implementation ideas from https://github.com/skainguyen1412/antigravity-usage. Used Claude Code and prompted with the below text.

Review the plugin in extensions/google-antigravity-auth. I want to implement a proper /usage
command to show token usage and cost for this provider.
Reference this repository for ideas on how to fetch the usage data from the Google Antigravity
(Cloud Code) APIs: https://github.com/skainguyen1412/antigravity-usage
Please explore the existing plugin code and the provided reference to propose an implementation
plan.

Then went through a few iterations. /status produces

🦞 Clawdbot 2026.1.21-2 (80c1edc)
🧠 Model: google-antigravity/gemini-3-flash
🧮 Tokens: 16k in / 188 out
📚 Context: 16k/1.0m (2%)
📊 Usage: Flash 80% left · Pro 100% left
🧵 Session: agent:dev:main
⚙️ Runtime: direct · Think: off · elevated

@patelhiren patelhiren marked this pull request as ready for review January 23, 2026 06:46
patelhiren and others added 2 commits January 23, 2026 07:15
- Add dedicated fetcher for google-antigravity provider
- Fetch credits and per-model quotas from Cloud Code API
- Report individual model IDs sorted by usage (top 10)
- Include comprehensive debug logging with [antigravity] prefix
@steipete steipete merged commit 4de660b into openclaw:main Jan 23, 2026
16 of 22 checks passed
@steipete
Copy link
Contributor

Landed via temp rebase onto main.\n\n- Gate: pnpm lint && pnpm build && pnpm test\n- Land commit: 1d38b50\n- Merge commit: 4de660b\n\nThanks @patelhiren!

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