[FEATURE] Sync Go usage from official /zen/go/v1/usage endpoint
✨ The feature
Have the Go usage status bar read Session (rolling 5h), Weekly, and Monthly meters from OpenCode's official /zen/go/v1/usage endpoint instead of estimating them locally. This makes the numbers account-wide and server-accurate.
🎯 The problem
Issue #23 reported drift from day one: the tracker showed "27d left" where opencode.ai said "19d left", and weekly/monthly percentages ran several points low. Root cause: OpenCode had no public usage API, so the extension had to estimate cost from tokens it saw and multiply by per-model pricing. That misses usage from the CLI/TUI, other devices, and anything before the extension was installed.
We shipped partial fixes: manual usage targets (#50) and a SQLite reader that pulls real billed amounts from the local opencode.db (#59/#60). They help, but SQLite is still per-machine, so cross-device usage stays out of the numbers.
Upstream just merged an official endpoint (anomalyco/opencode#16513): GET /zen/go/v1/usage. It authenticates with the same opencode-go key we already store in SecretStorage and returns rolling/weekly/monthly percent plus reset time computed server-side.
💡 Proposed solution
Add a sync layer in goUsageTracker:
- On refresh, call
GET https://opencode.ai/zen/go/v1/usagewith the existingopencodego.apiKeyfrom SecretStorage (same key and base URL as the models fetch). - Map the response onto
UsageSummary:usage.rolling→session(5h window, $12)usage.weekly→weekly($30)usage.monthly→monthly($60)- Use
resetsAtfor the "resets in" timer, which fixes the monthly anchor bug for real.
- Keep Today / Yesterday and per-session spend from local tracking + SQLite, since the API does not return those.
- Fall back to the current SQLite → tracked path when the API returns 401/403/404 or fails (offline, not live yet, no subscription).
- Never persist or log the key, and keep the existing "device only" wording for the local numbers.
🔄 Alternatives considered
- Manual sync from opencode.ai, already shipped as "Set Usage Targets". Works, but needs a re-sync whenever usage happens elsewhere.
- OAuth browser flow to read the dashboard directly. The upstream PR makes this unnecessary.
- Rate-limit headers on ordinary responses. Not shipped yet, and a dedicated endpoint is cleaner.
📋 Additional context
- Upstream PR: anomalyco/opencode#16513 (merged to
devAug 11 2026; confirm it is live in production before building on it). - Follows the same split as robinebers/openusage#1095: API for account-wide limits, local history for spend.
- Related: #23, #50, #59, #60.
- The extension already talks to
https://opencode.ai/zen/go/v1/*for models and chat completions, so no new auth surface is needed.
Working on this issue — the sync layer is implemented and being verified on the feat/issue-130-go-usage-sync branch:
src/goUsageSync.ts: fetchesGET /zen/go/v1/usagewith the existing Go key (failure classification: unauthorized / no-subscription / not-found / network / invalid) and merges the server-accurate rolling/weekly/monthly percent +resetsAtonto the local summary (60s TTL cache, graceful fallback to local estimates).- Wired on startup, per-request (uses the exact key of the request, covering BYOK groups), and status-bar refresh.
- Today/Yesterday/per-session spend stay device-local and are now labeled
ⓘ Counted locallyin the UI; the quick-pick Reset action was fixed (it previously did nothing). - 188/188 unit tests green; endpoint verified live in production.
Will open the PR once local verification is done.