feat(xai): surface Grok usage on quota dashboard via local usageHistory aggregation#2150
Open
DevEstacion wants to merge 4 commits into
Open
feat(xai): surface Grok usage on quota dashboard via local usageHistory aggregation#2150DevEstacion wants to merge 4 commits into
DevEstacion wants to merge 4 commits into
Conversation
xai has no public quota API, so aggregate prompt/completion/cost from local usageHistory over the last 30 days, grouped per model. Add xai to USAGE_SUPPORTED_PROVIDERS so the connection appears in the provider list. Tests cover aggregation, empty history, and connectionId scoping. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> (cherry picked from commit 16c6acf)
xAI has no public per-account quota endpoint. Route handler now uses getUsageHistory() to aggregate the last 30 days of prompt/completion tokens and cost per model for the current connection. Bypasses the better-sqlite3 ABI mismatch by staying on the existing localDb adapter that the service already loads. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> (cherry picked from commit 4a415c3)
Cumulative xAI rows (Total spend, Total tokens, per-model) have no cap. Without a total, calculatePercentage returns 0, which the color logic renders as '🔴 0%' — misleading for spend/totals. Mark these rows as unlimited + remaining: 100 so the dashboard shows the green badge and hides the bar. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> (cherry picked from commit 7ac6a5e)
…up dynamically Upstream derives USAGE_SUPPORTED_PROVIDERS from REGISTRY via `features.usage`. The hardcoded list in PR decolua#2148 was replaced by this registry flag so future provider additions don't need to edit providers.js.
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
Adds the xAI (Grok) quota dashboard. Aggregates 30-day usage from the local
usageHistorySQLite table since xAI has no public quota API.What it does
src/app/api/usage/[connectionId]/route.jsadds a fallback path that pulls Grok usage from the localusageHistorytable when the upstream quota API is unavailable. Returns aggregated quotas (Total spend, Total tokens) in the same shape as the other providers.unlimited: true+remaining: 100so the UI renders the green "100%" badge instead of a misleading "0%" progress bar.open-sse/providers/registry/xai.jsgainsfeatures.usage: trueso upstream's dynamicUSAGE_SUPPORTED_PROVIDERSfilter (derived from REGISTRY) picks xAI up automatically. Replaces the hardcoded list in the original commit.Files
src/app/api/usage/[connectionId]/route.js(+82)tests/unit/xai-usage.test.js(+99, new)open-sse/providers/registry/xai.js(+3,features.usage: true)Why route-handler aggregation (not service-layer)
The original implementation attempted a service-layer
getXaiUsageinopen-sse/services/usage.jsbut was reverted (0856aef) to avoid abetter-sqlite3ABI mismatch in the Node 25 runtime. This PR keeps aggregation in the route handler instead, which already runs in the Node-compatible Next.js context wherebetter-sqlite3works.Test plan
cd tests && ./node_modules/.bin/vitest run tests/unit/xai-usage.test.js🤖 Generated with opencode