feat(usage): unified usage tracking with auth refresh (#9281)#9545
Open
CasualDeveloper wants to merge 1 commit intoanomalyco:devfrom
Open
feat(usage): unified usage tracking with auth refresh (#9281)#9545CasualDeveloper wants to merge 1 commit intoanomalyco:devfrom
CasualDeveloper wants to merge 1 commit intoanomalyco:devfrom
Conversation
Contributor
|
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
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
7cdb698 to
46eca0b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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