feat(usage): unified usage tracking with auth refresh (#9281)#9545
feat(usage): unified usage tracking with auth refresh (#9281)#9545CasualDeveloper wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicates Found:1. PR #9301: feat(tui): add /usage command and sidebar usage section
2. PR #6905: feat: display Anthropic and OpenAI OAuth usage in status dialog and sidebar
3. PR #9069: feat: Multi-Account OAuth Rotation with Settings UI and CLI Enhancements
|
ba7d89c to
9ce0a41
Compare
06731ef to
a396eca
Compare
f0e277d to
60f388a
Compare
bd214cc to
a7d1cc1
Compare
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
4089f14 to
824997e
Compare
824997e to
7cdb698
Compare
3092b21 to
236d4d8
Compare
|
Ey @CasualDeveloper. What about this feature? 😜 |
236d4d8 to
3d3f5d7
Compare
Introduce a centralised `/usage` endpoint that fetches and caches rate-limit windows, credits and plan information for OpenAI ChatGPT, GitHub Copilot and Anthropic Claude. The server handles stale-while-revalidate caching (5 min TTL), per-provider error reporting and graceful fallback to cached data on network failures. - Add usage provider registry mapping auth keys to display names - Support two-call OAuth flow for Copilot usage token acquisition - Automatic token refresh on 401/expired Claude responses - TUI: shared usage client, dialog and sidebar components with live event-driven updates - Return structured `errors[]` alongside `entries[]` for granular UI feedback - Tests for usage endpoint and new Copilot-specific auth device flow - Regenerate SDK/OpenAPI with new Usage class and types Closes anomalyco#9281, anomalyco#728 Supersedes anomalyco#6905, anomalyco#7837 Alternate to anomalyco#9301
3d3f5d7 to
93b798d
Compare
@ciltocruz what do you mean lol. i've been keeping it updated alongside opencode dev releases and using it fine so far. is that not your experience haha |
I mean, if this feature is not going to be merged with the official repo. |
|
@ciltocruz I think we're just waiting for one of the maintainers to have some spare time to look into this. |
Summary
Add
/usageas the single source of truth for provider usage data (Codex, Copilot, Claude) with TUI integration and automatic token refresh. Users can now view rate limits via/usagecommand or sidebar panel, with provider-specific auth flows handling token expiry transparently.Closes #9281, closes #728
Supersedes #6905, #7837
Alternate implementation to #9301
Changes
Core
packages/opencode/src/usage/index.ts(~850 lines): usage fetchers for Codex (/backend-api/wham/usage), Copilot (/copilot_internal/user), Claude (/api/oauth/usage) with schema validation and cachingpackages/opencode/src/server/usage.ts:GET /usageendpoint with?provider=filter and?refresh=optionconsole.anthropic.com/v1/oauth/tokenusage.updatedbus event for sidebar syncAuth
packages/opencode/src/cli/cmd/auth.ts: second device-flow prompt during Copilot login using VS Code client ID (Iv1.b507a08c87ecfe98) to captureusagetoken forcopilot_internal/userpackages/opencode/src/auth/index.ts: optionalusagefield in OAuth schemapackages/opencode/src/plugin/copilot.ts: attempt service token exchange viacopilot_internal/v2/token; fallback to device tokenpackages/opencode/src/provider/auth.ts: persistusagetokenTUI
dialog-usage.tsx: renders usage windows with progress bars, reset times, credits/quotaprompt/index.tsx:/usagecommand with--current,--allflags; always fetches fresh datasidebar.tsx: collapsible Usage panel; refreshes onusage.updatedevents and assistant turn completionpackages/opencode/src/config/config.ts:tui.show_usage_provider_scopesetting ("current"|"all")SDK/OpenAPI
packages/sdk/openapi.jsonandpackages/sdk/js/src/v2/gen/types.gen.tsTests
packages/opencode/test/server/usage.test.ts: mock auth scenarios, provider filtering, error handlingAI Assistance
bun turbo typecheck&&bun run --cwd packages/opencode test test/server/usage.test.ts&&bun run --cwd packages/opencode build)Notes
bun turbo testnot run this sessiontui.show_usage_provider_scopeconfig