Skip to content

fix(cursor): fall back to /api/usage-summary for enterprise/team accounts#846

Open
robinebers wants to merge 1 commit into
mainfrom
fix/cursor-usage-summary-fallback
Open

fix(cursor): fall back to /api/usage-summary for enterprise/team accounts#846
robinebers wants to merge 1 commit into
mainfrom
fix/cursor-usage-summary-fallback

Conversation

@robinebers

Copy link
Copy Markdown
Owner

Fixes #829

TL;DR

Enterprise/team Cursor accounts no longer error out — OpenUsage now falls back to the dashboard's /api/usage-summary endpoint, which is the one that actually returns usage for those accounts.

What was happening

  • Enterprise and team (TOKEN_BASED_CONTRACT) accounts showed "Enterprise usage data unavailable. Try again later."
  • GetCurrentPeriodUsage returns no usable planUsage for these accounts, and the request-based /api/usage fallback returns null limits, so both existing paths came up empty.

What this changes

  • New fetchUsageSummary call in CursorUsageClient: GET cursor.com/api/usage-summary, authenticated with the same WorkosCursorSessionToken cookie the other REST calls already derive from the access token (no browser cookies).
  • New CursorUsageMapper.mapUsageSummary: maps teamUsage.pooled → dollar Total Usage meter (when limitType is 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.
  • CursorProvider tries 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: docs/providers/cursor.md under-the-hood section mentions the new fallback.

Heads-up

Tests

  • Mapper unit tests using the exact fixture from the issue (pooled team limit, individual limit, unusable payload → nil).
  • End-to-end provider test: enterprise account with empty planUsage now renders dollar meters via usage-summary instead of erroring.
  • Full swift test suite passes.

Made with Cursor

…unts (#829)

Co-authored-by: Cursor <cursoragent@cursor.com>
@robinebers robinebers added the gate-passed Passed the automated PR gatekeeper checks (gatekeeper skips it on later runs) label Jul 3, 2026 — with Cursor
@robinebers

Copy link
Copy Markdown
Owner Author

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.

@validatedev

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +120 to +121
if let mapped = await usageSummaryResult(accessToken: currentToken, planName: planName) {
return snapshot(mapped)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs gate-passed Passed the automated PR gatekeeper checks (gatekeeper skips it on later runs) provider tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enterprise/team accounts fail: usage-summary endpoint not used as fallback

2 participants