Fix Cursor usage always reporting 0 under credit-based pricing (#7)#8
Open
leek wants to merge 2 commits into
Open
Fix Cursor usage always reporting 0 under credit-based pricing (#7)#8leek wants to merge 2 commits into
leek wants to merge 2 commits into
Conversation
CursorUsageProvider summed `numRequests` from the legacy `/api/usage` endpoint. Cursor froze those per-model request counters at 0 when it moved to credit/usage-based pricing in June 2025, so the provider always reported 0 regardless of actual activity. Read real usage from `dashboard/get-aggregated-usage-events` instead and report dollars spent in the current billing period (`totalCostCents / 100`) using the existing `.dollars` unit. The legacy endpoint is kept solely for the `startOfMonth` billing anchor (period window + reset time). The dashboard endpoint requires an `Origin: https://cursor.com` header or it returns 403, so that is now sent. Cursor's per-plan limit becomes a USD allotment (`CursorPlan.monthlyUsageLimitUSD`) and the Settings field is relabeled from requests to USD. Tests updated to cover the dollar metric, the aggregations fallback, and the required Origin header. Fixes scari#7
Aggregating a full billing period of usage events is slow on a cold request; the default 10s timeout caused the first several polls to time out (falling back to stale cache) before a fetch succeeded. Give that call 30s while keeping the lightweight legacy call at 10s.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #7 — the Cursor entry always shows 0 usage on accounts using Cursor's current credit/usage-based pricing.
CursorUsageProvidersummednumRequestsfrom the legacyhttps://www.cursor.com/api/usageendpoint. Cursor froze those per-model request counters at0when it moved to credit-based pricing in June 2025, so the provider reported0even for accounts with heavy, paid usage. (The Settings panel already noted "Credit-based pricing since June 2025" — the provider just never followed.)What changed
dashboard/get-aggregated-usage-eventsand report dollars spent this billing period (totalCostCents / 100) via the existing.dollarsUsageUnit, whichDetailPopoverViewandUsageHistoryTabViewalready render./api/usagecall is kept only forstartOfMonth(billing-period window + reset time).Origin: https://cursor.comit returns403 {"error":"Invalid origin for state-changing request"}— so that header is now sent.CursorPlanexposes a USD allotment (monthlyUsageLimitUSD) instead ofmonthlyRequestEstimate; the Settings limit field is relabeled from "requests" to "USD" and the view-model wiring follows.aggregations[].totalCentsif the server omits the top-level total, and tostartOfCurrentMonthUTC()/firstOfNextMonthUTC()whenstartOfMonthis missing. Existing disk cache +cachedOrThrowbehavior is preserved.API reference
Testing
xcodebuild test -scheme AgentBar -destination 'platform=macOS'→ 287 tests, 0 failures (1 pre-existing skip).CursorUsageProviderTestsrewritten for the dollar metric: dollars-from-totalCostCents, aggregations-sum fallback, reset fromstartOfMonth, plan limit as total, and the requiredOriginheader. The mock URL protocol now routes the legacy GET and aggregated POST to separate stubs./api/usagereturnsnumRequests: 0, while the aggregated endpoint returns the correct period spend.Notes
.customlets users set their own. The displayedusedvalue is exact from the API.cursorMonthlyLimitdefault is now interpreted as USD; non-custom plans overwrite it on selection, so only a.customuser with a stale stored request count would need to re-enter it once.