feat(xai): surface Grok usage on quota dashboard - #5806
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Code Review
This pull request implements self-tracked cumulative usage tracking for xAI (Grok) by querying locally routed tokens, as xAI lacks a public quota API. It also adds comprehensive unit tests for this new provider. The review feedback suggests calculating and providing the actual monthly reset timestamp for the resetAt field instead of hardcoding it to null, ensuring the dashboard accurately displays when the usage count resets.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| return { | ||
| plan: "xAI / Grok (OmniRoute-tracked)", | ||
| quotas: { | ||
| monthly: { | ||
| used, | ||
| total: 0, | ||
| remaining: 100, | ||
| remainingPercentage: 100, | ||
| resetAt: null, | ||
| unlimited: true, | ||
| } as UsageQuota, | ||
| }, | ||
| }; |
There was a problem hiding this comment.
Since xAI usage is tracked on a monthly basis using getMonthlyProviderTokensForConnection, the usage will reset at the start of each calendar month. Hardcoding resetAt to null is misleading for the user as the dashboard won't display when the usage resets, and the count will suddenly drop to 0 on the 1st of the next month. We should calculate and provide the actual reset timestamp (the start of the next UTC month), mirroring the pattern used in getXiaomiMimoUsage.
const now = new Date();
const resetAt = new Date(
Date.UTC(now.getUTCFullYear(), now.getUTCMonth() + 1, 1)
).toISOString();
return {
plan: "xAI / Grok (OmniRoute-tracked)",
quotas: {
monthly: {
used,
total: 0,
remaining: 100,
remainingPercentage: 100,
resetAt,
unlimited: true,
} as UsageQuota,
},
};…ry aggregation xAI has no public per-account quota API (the billing console requires a session cookie, not an API key). Add getXaiUsage(connectionId), mirroring the existing Xiaomi MiMo self-track pattern: sum tokens routed to the connection from usage_history via getMonthlyProviderTokensForConnection and surface them as a cumulative, uncapped quota (unlimited: true, remaining: 100 — xAI has no fixed monthly cap). Register 'xai' in USAGE_FETCHER_PROVIDERS and wire a switch case in getUsageForProvider. Co-authored-by: ron <devestacion@gmail.com> Inspired-by: decolua/9router#2150
51fb769 to
57d2893
Compare
…ry aggregation (diegosouzapw#5806) xAI has no public per-account quota API (the billing console requires a session cookie, not an API key). Add getXaiUsage(connectionId), mirroring the existing Xiaomi MiMo self-track pattern: sum tokens routed to the connection from usage_history via getMonthlyProviderTokensForConnection and surface them as a cumulative, uncapped quota (unlimited: true, remaining: 100 — xAI has no fixed monthly cap). Register 'xai' in USAGE_FETCHER_PROVIDERS and wire a switch case in getUsageForProvider. Inspired-by: decolua/9router#2150 Co-authored-by: ron <devestacion@gmail.com>
Summary
xAI (Grok) had no usage-dashboard support:
xaiwas absent fromUSAGE_FETCHER_PROVIDERSand had no case ingetUsageForProvider, so the quota dashboard showed nothing for xAI connections. xAI also has no public per-account quota API — the billing console at console.x.ai requires a session cookie, not an API key.This adds local, self-tracked usage for xAI, mirroring the existing Xiaomi MiMo self-track pattern: OmniRoute sums the tokens it itself routed to the connection (from
usage_history) and surfaces them on the quota dashboard. Unlike Xiaomi MiMo, xAI has no fixed monthly cap, so the aggregate is reported asunlimited: truewithremaining: 100— this renders the dashboard's green "100%" badge instead of a meaningless progress bar against a zero total.Changes
open-sse/services/usage.tsgetXaiUsage(connectionId)— aggregates tokens viagetMonthlyProviderTokensForConnection("xai", connectionId)(fromsrc/lib/usage/usageStats.ts) and returns a cumulative{ unlimited: true, remaining: 100 }quota, provider + connection-scoped."xai"inUSAGE_FETCHER_PROVIDERS.case "xai"togetUsageForProviderdelegating togetXaiUsage.getXaiUsagefrom__testing.CHANGELOG.md— new-features entry.tests/unit/xai-usage.test.ts— new regression test (real temp SQLite DB).The usage route handler (
src/app/api/usage/[connectionId]/route.ts) is a thin delegator and is intentionally left untouched.Attribution
Thanks to @DevEstacion for the original implementation.
Testing
New
tests/unit/xai-usage.test.ts(node:test, real tempDATA_DIRSQLite DB, withresetDbInstance()+ temp cleanup intest.after):usage_historyrows for axaiconnection at now / out-of-window / a different connection / a different provider;getXaiUsage/getUsageForProvider("xai", ...)aggregate only in-window rows for the target connection (no provider/connection bleed);unlimited: truewithremaining: 100;"xai"is registered inUSAGE_FETCHER_PROVIDERS.TDD: failed first (function/registration absent), passes after the implementation — 7/7 green.
npm run typecheck:coreclean;eslintclean on changed files. The existingtests/unit/xiaomi-mimo-selftrack-usage.test.tsstays green (no regression).