Skip to content

feat(xai): surface Grok usage on quota dashboard via local usageHistory aggregation#2150

Open
DevEstacion wants to merge 4 commits into
decolua:masterfrom
DevEstacion:pr/7-xai-quota-dashboard
Open

feat(xai): surface Grok usage on quota dashboard via local usageHistory aggregation#2150
DevEstacion wants to merge 4 commits into
decolua:masterfrom
DevEstacion:pr/7-xai-quota-dashboard

Conversation

@DevEstacion

Copy link
Copy Markdown

Summary

Adds the xAI (Grok) quota dashboard. Aggregates 30-day usage from the local usageHistory SQLite table since xAI has no public quota API.

What it does

  • Route handler aggregationsrc/app/api/usage/[connectionId]/route.js adds a fallback path that pulls Grok usage from the local usageHistory table when the upstream quota API is unavailable. Returns aggregated quotas (Total spend, Total tokens) in the same shape as the other providers.
  • Cumulative rows marked unlimited — Grok cumulative rows (Total spend, Total tokens) have no hard cap. The fix sets unlimited: true + remaining: 100 so the UI renders the green "100%" badge instead of a misleading "0%" progress bar.
  • Provider registry flagopen-sse/providers/registry/xai.js gains features.usage: true so upstream's dynamic USAGE_SUPPORTED_PROVIDERS filter (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 getXaiUsage in open-sse/services/usage.js but was reverted (0856aef) to avoid a better-sqlite3 ABI 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 where better-sqlite3 works.

Test plan

  • cd tests && ./node_modules/.bin/vitest run tests/unit/xai-usage.test.js
  • Manual: hit the quota dashboard with an xAI connection → verify Grok quota row renders with the green unlimited badge.

🤖 Generated with opencode

DevEstacion and others added 4 commits June 26, 2026 22:59
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant