Skip to content

Commit 81e95dc

Browse files
jakeleventhalclaude
andcommitted
fix(server): Grok accounts with no usage yet no longer vanish from Limits
xAI omits `creditUsagePercent` from its billing response entirely until an account has accrued metered usage, rather than sending 0. We treated that absence as `unsupported`, which the contract reserves for accounts that can never report quota, such as API keys and Bedrock. The Limits view drops those accounts and deliberately mutes their notice, so a freshly signed-in Grok account disappeared from Usage with no bar and no explanation until it happened to be used. `applyUsageLimitsUpdate` also refuses mid-turn windows for an `unsupported` snapshot, so nothing could recover it in the meantime. Report no windows instead, leaving the `unavailable` marker off. The account keeps its row and gets the existing "No limits reported." notice, and the bar appears on its own once usage registers. The genuine can-never-report paths in `readGrokUsageLimits` (API key, alternate auth deployments, custom config) still return `unsupported` and are unaffected. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 2d8f9a8 commit 81e95dc

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎apps/server/src/provider/Layers/GrokProvider.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,10 @@ describe("Grok usage limits", () => {
564564
for (const response of [{}, { config: {} }, { config: { creditUsagePercent: NaN } }]) {
565565
const limits = grokUsageResponseToLimits(response, checkedAt);
566566
expect(limits.windows).toEqual([]);
567-
expect(limits.unavailable?.reason).toBe("unsupported");
567+
// Nothing metered yet, which xAI reports by omitting the field until
568+
// usage registers. Marking it `unsupported` would drop the account from
569+
// the Limits view for good; leaving the marker off keeps it listed.
570+
expect(limits.unavailable).toBeUndefined();
568571
}
569572
expect(
570573
grokUsageResponseToLimits({ config: { creditUsagePercent: 0 } }, checkedAt).windows,

‎apps/server/src/provider/Layers/grokUsageLimits.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ export function grokUsageResponseToLimits(
4141
) {
4242
const usedPercent = response.config?.creditUsagePercent;
4343
if (usedPercent === undefined || !Number.isFinite(usedPercent)) {
44-
return makeUnavailableUsageLimits({ checkedAt, reason: "unsupported" });
44+
// A billing read that succeeded but carries no percentage is an account
45+
// with nothing metered yet, not one that can never report: xAI omits the
46+
// field entirely (rather than sending 0) until usage registers, then fills
47+
// it in. Calling that `unsupported` would strand the account — the Limits
48+
// view drops unsupported entries and deliberately mutes their notice, so a
49+
// freshly signed-in Grok account would vanish with no explanation until it
50+
// happened to be used, and `applyUsageLimitsUpdate` would refuse the
51+
// mid-turn windows that could have recovered it.
52+
return makeUsageLimits({ checkedAt, windows: [] });
4553
}
4654
const period = response.config?.currentPeriod;
4755
const periodType = period?.type?.replace(/^USAGE_PERIOD_TYPE_/, "");

0 commit comments

Comments
 (0)