[Feat] Show subscription provider usage on Models settings#580
Merged
Conversation
Fetch usage/quota for ChatGPT, GitHub Copilot, and Kimi for Coding server-side using the credentials the deployment already holds, expose it via an admin-gated subscriptionUsage.list tRPC query, and render a usage line under each provider row in Settings > Models. The upstream usage endpoints are unofficial (each is what the provider's own CLI polls), so parsers accept known field aliases and any failure just hides the usage line instead of erroring the page.
Contributor
|
No new code issues found. See task
Reviewed 73a786d |
…mponent test mocks - Invalidate subscriptionUsage.list after saving/deleting a provider, disconnecting a subscription, and completing either connect dialog, so the usage line refreshes with the provider state instead of staying fresh for up to a minute. - Extend the InferenceProviderSection test tRPC/useQuery mocks with the new subscriptionUsage dependency and add coverage for the usage line (rendered under connected rows, hidden on errored rows or missing data).
Contributor
Author
|
Addressed the review feedback:
|
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.
What
Adds a usage line under the ChatGPT, GitHub Copilot, and Kimi for Coding provider rows in Settings > Models, showing current plan usage such as remaining Copilot premium requests or percent used of the 5-hour and weekly rate-limit windows, with reset times.
How
packages/types: new normalizedSubscriptionProviderUsage/SubscriptionUsageWindowtypes plus the provider usage endpoint constants.packages/db:getSubscriptionProviderUsage()with one fetcher per provider, reusing credentials the deployment already holds:copilot_internal/userwith the stored OAuth token, reading thepremium_interactionsquota snapshot.backend-api/wham/usageviagetFreshChatGptAccessToken(), so it rides the existing advisory-locked refresh.KIMI_API_KEY, with a/v1/usagefallback on 404.apps/web: admin-gatedsubscriptionUsage.listtRPC query and the usage line rendering inInferenceProviderSection(1 minute stale time). Only normalized numbers reach the client, never tokens.apps/docs: short note on the new usage display inmodels.mdx.Notes on the upstream endpoints
None of these usage endpoints are officially documented; each is the endpoint the provider's own CLI polls for its usage display. Live payloads were verified against all three providers and differ in places from what third-party tooling documents (ChatGPT now nests windows under a singular
rate_limitkey; Kimi serializes numbers as strings and uses proto-style enum values). Parsers accept the known field aliases, the live shapes are pinned in tests, and any fetch/parse failure resolves to null so the UI omits the usage line rather than erroring. Window labels are derived from the reported window durations rather than hardcoded, so label text survives upstream window changes.Testing
pnpm lint,pnpm check-types,pnpm knip, and the fullpackages/dblib suite pass.