Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/server/src/provider/Layers/GrokProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,10 @@ describe("Grok usage limits", () => {
for (const response of [{}, { config: {} }, { config: { creditUsagePercent: NaN } }]) {
const limits = grokUsageResponseToLimits(response, checkedAt);
expect(limits.windows).toEqual([]);
expect(limits.unavailable?.reason).toBe("unsupported");
// Nothing metered yet, which xAI reports by omitting the field until
// usage registers. Marking it `unsupported` would drop the account from
// the Limits view for good; leaving the marker off keeps it listed.
expect(limits.unavailable).toBeUndefined();
}
expect(
grokUsageResponseToLimits({ config: { creditUsagePercent: 0 } }, checkedAt).windows,
Expand Down
10 changes: 9 additions & 1 deletion apps/server/src/provider/Layers/grokUsageLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ export function grokUsageResponseToLimits(
) {
const usedPercent = response.config?.creditUsagePercent;
if (usedPercent === undefined || !Number.isFinite(usedPercent)) {
return makeUnavailableUsageLimits({ checkedAt, reason: "unsupported" });
// A billing read that succeeded but carries no percentage is an account
// with nothing metered yet, not one that can never report: xAI omits the
// field entirely (rather than sending 0) until usage registers, then fills
// it in. Calling that `unsupported` would strand the account — the Limits
// view drops unsupported entries and deliberately mutes their notice, so a
// freshly signed-in Grok account would vanish with no explanation until it
// happened to be used, and `applyUsageLimitsUpdate` would refuse the
// mid-turn windows that could have recovered it.
Comment on lines +44 to +51

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the t3 team has collaborated with grok, maybe something to ask them to fix on their end

return makeUsageLimits({ checkedAt, windows: [] });
}
const period = response.config?.currentPeriod;
const periodType = period?.type?.replace(/^USAGE_PERIOD_TYPE_/, "");
Expand Down
Loading