fix(cursor): fall back to /api/usage-summary for enterprise/team accounts#846
fix(cursor): fall back to /api/usage-summary for enterprise/team accounts#846robinebers wants to merge 1 commit into
Conversation
…unts (#829) Co-authored-by: Cursor <cursoragent@cursor.com>
|
Heads-up: #832 by @andyli-star is a parallel implementation of the same fix. We're consolidating on this PR — see the comment there for what was kept and what's deferred (Team Pool widget, display-message percent parsing, credits/spend in the enterprise path). Enterprise-account verification for this PR is pending from the folks on #829/#832. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2bfe518f91
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if let mapped = await usageSummaryResult(accessToken: currentToken, planName: planName) { | ||
| return snapshot(mapped) |
There was a problem hiding this comment.
Restrict usage-summary fallback to team accounts
When GetPlanInfo is temporarily unavailable, shouldUseRequestBasedFallback also returns shouldFallback for accounts whose type is unknown, not just enterprise/team accounts. In that scenario, a request-based Cursor account can now stop here if /api/usage-summary returns any individual meter, so the provider returns a Total Usage dollar line and never reaches the existing /api/usage?user=... path that produces the Requests metric. Gate this call on a confirmed enterprise/team signal, or keep falling through to the request-based fallback when the plan is unknown.
Useful? React with 👍 / 👎.
Fixes #829
TL;DR
Enterprise/team Cursor accounts no longer error out — OpenUsage now falls back to the dashboard's
/api/usage-summaryendpoint, which is the one that actually returns usage for those accounts.What was happening
TOKEN_BASED_CONTRACT) accounts showed "Enterprise usage data unavailable. Try again later."GetCurrentPeriodUsagereturns no usableplanUsagefor these accounts, and the request-based/api/usagefallback returnsnulllimits, so both existing paths came up empty.What this changes
fetchUsageSummarycall inCursorUsageClient:GET cursor.com/api/usage-summary, authenticated with the sameWorkosCursorSessionTokencookie the other REST calls already derive from the access token (no browser cookies).CursorUsageMapper.mapUsageSummary: mapsteamUsage.pooled→ dollar Total Usage meter (whenlimitTypeis team),individualUsage.overall→ Total Usage otherwise,teamUsage.onDemand→ On-demand meter, and billing cycle from the ISO dates. Values are cents; disabled/zero-limit meters are skipped defensively.CursorProvidertries usage-summary first whenever the existing enterprise/team fallback detection fires; any failure falls through to the current request-based path, so behavior can only improve.docs/providers/cursor.mdunder-the-hood section mentions the new fallback.Heads-up
limitType, missingteamUsage) are handled defensively and degrade to today's behavior.Tests
planUsagenow renders dollar meters via usage-summary instead of erroring.swift testsuite passes.Made with Cursor