diff --git a/apps/mobile/src/i18n/translations/de.json b/apps/mobile/src/i18n/translations/de.json index 661efe1306eb0..37307cb59330b 100644 --- a/apps/mobile/src/i18n/translations/de.json +++ b/apps/mobile/src/i18n/translations/de.json @@ -5713,5 +5713,7 @@ "99451a5d2d40440f": "Zurückgezogen von {by}.", "3ee30a50b70fffab": "Zurückgezogen von {by}: {reason}", "201490988858b511": "zurückgezogen von {by}", - "46d614fa7b4bf1e5": "Workflow-Ausführungen" + "46d614fa7b4bf1e5": "Workflow-Ausführungen", + "c7566c908e14be09": "Ausgaben", + "ae693772acb75c75": "Ausgaben in diesem Abrechnungszeitraum im Verhältnis zu deinem {provider}-Ausgabenlimit." } diff --git a/apps/mobile/src/i18n/translations/en.json b/apps/mobile/src/i18n/translations/en.json index 01839be0196ed..f0ee4ca6c0dde 100644 --- a/apps/mobile/src/i18n/translations/en.json +++ b/apps/mobile/src/i18n/translations/en.json @@ -5715,5 +5715,7 @@ "99451a5d2d40440f": "Withdrawn by {by}.", "3ee30a50b70fffab": "Withdrawn by {by}: {reason}", "201490988858b511": "withdrawn by {by}", - "46d614fa7b4bf1e5": "Workflow runs" + "46d614fa7b4bf1e5": "Workflow runs", + "c7566c908e14be09": "Spend", + "ae693772acb75c75": "Spending this billing cycle against your {provider} spend limit." } diff --git a/apps/mobile/src/i18n/translations/es.json b/apps/mobile/src/i18n/translations/es.json index f5b5d4e717a3b..a1c913e617eb0 100644 --- a/apps/mobile/src/i18n/translations/es.json +++ b/apps/mobile/src/i18n/translations/es.json @@ -5707,5 +5707,7 @@ "99451a5d2d40440f": "Retirada por {by}.", "3ee30a50b70fffab": "Retirada por {by}: {reason}", "201490988858b511": "retirada por {by}", - "46d614fa7b4bf1e5": "Ejecuciones de flujos de trabajo" + "46d614fa7b4bf1e5": "Ejecuciones de flujos de trabajo", + "c7566c908e14be09": "Gasto", + "ae693772acb75c75": "Gasto de este ciclo de facturación respecto a tu límite de gasto de {provider}." } diff --git a/apps/mobile/src/i18n/translations/fr.json b/apps/mobile/src/i18n/translations/fr.json index 12b52d16103c1..7dc121ba9e032 100644 --- a/apps/mobile/src/i18n/translations/fr.json +++ b/apps/mobile/src/i18n/translations/fr.json @@ -5707,5 +5707,7 @@ "99451a5d2d40440f": "Retirée par {by}.", "3ee30a50b70fffab": "Retirée par {by} : {reason}", "201490988858b511": "retirée par {by}", - "46d614fa7b4bf1e5": "Exécutions de workflow" + "46d614fa7b4bf1e5": "Exécutions de workflow", + "c7566c908e14be09": "Dépenses", + "ae693772acb75c75": "Dépenses de ce cycle de facturation par rapport à votre limite de dépenses {provider}." } diff --git a/apps/mobile/src/i18n/translations/ja.json b/apps/mobile/src/i18n/translations/ja.json index 6524d9252b7bb..2072504d85ff2 100644 --- a/apps/mobile/src/i18n/translations/ja.json +++ b/apps/mobile/src/i18n/translations/ja.json @@ -5684,5 +5684,7 @@ "99451a5d2d40440f": "{by} が取り下げました。", "3ee30a50b70fffab": "{by} が取り下げました: {reason}", "201490988858b511": "{by} が取り下げ", - "46d614fa7b4bf1e5": "ワークフローの実行" + "46d614fa7b4bf1e5": "ワークフローの実行", + "c7566c908e14be09": "支出", + "ae693772acb75c75": "この請求期間の支出と{provider}の支出上限。" } diff --git a/apps/mobile/src/i18n/translations/ko.json b/apps/mobile/src/i18n/translations/ko.json index ccfd226483137..d7ab03133c859 100644 --- a/apps/mobile/src/i18n/translations/ko.json +++ b/apps/mobile/src/i18n/translations/ko.json @@ -5691,5 +5691,7 @@ "99451a5d2d40440f": "{by}에서 철회했습니다.", "3ee30a50b70fffab": "{by}에서 철회했습니다: {reason}", "201490988858b511": "{by}에서 철회함", - "46d614fa7b4bf1e5": "워크플로 실행" + "46d614fa7b4bf1e5": "워크플로 실행", + "c7566c908e14be09": "지출", + "ae693772acb75c75": "이번 청구 주기의 지출과 {provider} 지출 한도." } diff --git a/apps/mobile/src/i18n/translations/pt-BR.json b/apps/mobile/src/i18n/translations/pt-BR.json index b3b91ac88165c..a1444cba1228f 100644 --- a/apps/mobile/src/i18n/translations/pt-BR.json +++ b/apps/mobile/src/i18n/translations/pt-BR.json @@ -5707,5 +5707,7 @@ "99451a5d2d40440f": "Retirada por {by}.", "3ee30a50b70fffab": "Retirada por {by}: {reason}", "201490988858b511": "retirada por {by}", - "46d614fa7b4bf1e5": "Execuções de workflow" + "46d614fa7b4bf1e5": "Execuções de workflow", + "c7566c908e14be09": "Gastos", + "ae693772acb75c75": "Gastos neste ciclo de cobrança em relação ao seu limite de gastos do {provider}." } diff --git a/apps/mobile/src/i18n/translations/ru.json b/apps/mobile/src/i18n/translations/ru.json index 2a6137baf4f7e..18ec150c817a5 100644 --- a/apps/mobile/src/i18n/translations/ru.json +++ b/apps/mobile/src/i18n/translations/ru.json @@ -5787,5 +5787,7 @@ "99451a5d2d40440f": "Отозван: {by}.", "3ee30a50b70fffab": "Отозван ({by}): {reason}", "201490988858b511": "отозван: {by}", - "46d614fa7b4bf1e5": "Запуски воркфлоу" + "46d614fa7b4bf1e5": "Запуски воркфлоу", + "c7566c908e14be09": "Расходы", + "ae693772acb75c75": "Расходы за текущий расчётный период относительно лимита расходов {provider}." } diff --git a/apps/mobile/src/i18n/translations/sv.json b/apps/mobile/src/i18n/translations/sv.json index b511788c4a6ad..d9f6948e1c564 100644 --- a/apps/mobile/src/i18n/translations/sv.json +++ b/apps/mobile/src/i18n/translations/sv.json @@ -5713,5 +5713,7 @@ "99451a5d2d40440f": "Återkallad av {by}.", "3ee30a50b70fffab": "Återkallad av {by}: {reason}", "201490988858b511": "återkallad av {by}", - "46d614fa7b4bf1e5": "Arbetsflödeskörningar" + "46d614fa7b4bf1e5": "Arbetsflödeskörningar", + "c7566c908e14be09": "Utgifter", + "ae693772acb75c75": "Utgifter under denna faktureringsperiod i förhållande till din utgiftsgräns i {provider}." } diff --git a/apps/mobile/src/i18n/translations/zh.json b/apps/mobile/src/i18n/translations/zh.json index 62f4adad73023..f3b1ef39fe355 100644 --- a/apps/mobile/src/i18n/translations/zh.json +++ b/apps/mobile/src/i18n/translations/zh.json @@ -5694,5 +5694,7 @@ "99451a5d2d40440f": "已由 {by} 撤回。", "3ee30a50b70fffab": "已由 {by} 撤回:{reason}", "201490988858b511": "已由 {by} 撤回", - "46d614fa7b4bf1e5": "工作流运行" + "46d614fa7b4bf1e5": "工作流运行", + "c7566c908e14be09": "支出", + "ae693772acb75c75": "本计费周期的支出与 {provider} 支出限额。" } diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json index dd2048e35e207..8a23e86af91fd 100644 --- a/apps/web/src/i18n/translations/de.json +++ b/apps/web/src/i18n/translations/de.json @@ -13023,5 +13023,7 @@ "v": "v" }, " weitere unter Verknüpfte Elemente" - ] + ], + "c7566c908e14be09": "Ausgaben", + "ae693772acb75c75": "Ausgaben in diesem Abrechnungszeitraum im Verhältnis zu deinem {provider}-Ausgabenlimit." } diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json index cd649d26d9589..152b094ae5ad4 100644 --- a/apps/web/src/i18n/translations/en.json +++ b/apps/web/src/i18n/translations/en.json @@ -13031,5 +13031,7 @@ "v": "v" }, " more in Linked items" - ] + ], + "c7566c908e14be09": "Spend", + "ae693772acb75c75": "Spending this billing cycle against your {provider} spend limit." } diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json index daba2e1592d6e..5b48c1c255efc 100644 --- a/apps/web/src/i18n/translations/es.json +++ b/apps/web/src/i18n/translations/es.json @@ -13018,5 +13018,7 @@ "v": "v" }, " más en Elementos vinculados" - ] + ], + "c7566c908e14be09": "Gasto", + "ae693772acb75c75": "Gasto de este ciclo de facturación respecto a tu límite de gasto de {provider}." } diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json index 58602129396a4..fac5babf259f3 100644 --- a/apps/web/src/i18n/translations/fr.json +++ b/apps/web/src/i18n/translations/fr.json @@ -13023,5 +13023,7 @@ "v": "v" }, " de plus dans Éléments associés" - ] + ], + "c7566c908e14be09": "Dépenses", + "ae693772acb75c75": "Dépenses de ce cycle de facturation par rapport à votre limite de dépenses {provider}." } diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json index 5ba2bb830203b..48a7a07dcf171 100644 --- a/apps/web/src/i18n/translations/ja.json +++ b/apps/web/src/i18n/translations/ja.json @@ -12959,5 +12959,7 @@ "v": "v" }, " 件をリンクされた項目で表示" - ] + ], + "c7566c908e14be09": "支出", + "ae693772acb75c75": "この請求期間の支出と{provider}の支出上限。" } diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json index 4501bb0aa565a..4b9989d291d9c 100644 --- a/apps/web/src/i18n/translations/ko.json +++ b/apps/web/src/i18n/translations/ko.json @@ -12956,5 +12956,7 @@ "v": "v" }, "개 더 보기" - ] + ], + "c7566c908e14be09": "지출", + "ae693772acb75c75": "이번 청구 주기의 지출과 {provider} 지출 한도." } diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json index 1c1f0c659a2a2..7bfcccbba4015 100644 --- a/apps/web/src/i18n/translations/pt-BR.json +++ b/apps/web/src/i18n/translations/pt-BR.json @@ -13023,5 +13023,7 @@ "v": "v" }, " mais em Itens vinculados" - ] + ], + "c7566c908e14be09": "Gastos", + "ae693772acb75c75": "Gastos neste ciclo de cobrança em relação ao seu limite de gastos do {provider}." } diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json index 931ec1676a800..1b92f87f3b928 100644 --- a/apps/web/src/i18n/translations/ru.json +++ b/apps/web/src/i18n/translations/ru.json @@ -13022,5 +13022,7 @@ "v": "v" }, " в разделе «Привязанные элементы»" - ] + ], + "c7566c908e14be09": "Расходы", + "ae693772acb75c75": "Расходы за текущий расчётный период относительно лимита расходов {provider}." } diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json index 73b4ba6181f4b..70801104154b0 100644 --- a/apps/web/src/i18n/translations/sv.json +++ b/apps/web/src/i18n/translations/sv.json @@ -13030,5 +13030,7 @@ "v": "v" }, " till i Länkade objekt" - ] + ], + "c7566c908e14be09": "Utgifter", + "ae693772acb75c75": "Utgifter under denna faktureringsperiod i förhållande till din utgiftsgräns i {provider}." } diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json index 8fd7202ec7c10..3a9954c48ea24 100644 --- a/apps/web/src/i18n/translations/zh.json +++ b/apps/web/src/i18n/translations/zh.json @@ -13037,5 +13037,7 @@ "v": "v" }, " 项" - ] + ], + "c7566c908e14be09": "支出", + "ae693772acb75c75": "本计费周期的支出与 {provider} 支出限额。" } diff --git a/docs/user/usage.md b/docs/user/usage.md index 9da54a1e0e370..d32b923dd2f8b 100644 --- a/docs/user/usage.md +++ b/docs/user/usage.md @@ -35,7 +35,7 @@ Usage aggregates history across Codex, Claude Code, Grok Build, OpenCode, Antigr - **Reset credits**: Click an account segment/row to inspect plan details and redeem banked Codex/Claude reset credits via **Use reset** (Claude resets unavailable on macOS Keychain logins). - **Provider notes**: - **OpenCode**: OpenCode 2 servers with usage reporting show Go allowances and Console budgets for the connected workspace. Local servers can also report Go usage from a Go API key (`OPENCODE_API_KEY`). - - **Cursor**: Reports monthly Auto + API quotas via `CURSOR_AUTH_TOKEN` or default-endpoint sign-in/`CURSOR_API_KEY`. + - **Cursor**: Reports monthly Auto + API quotas via `CURSOR_AUTH_TOKEN` or default-endpoint sign-in/`CURSOR_API_KEY`. Enterprise accounts can show a Spend bar against the reported spend limit; accounts without reported limits link to the Cursor usage dashboard. - **Grok**: Reports billing-period quotas for `grok login` (not `XAI_API_KEY`). - **Muse Code**: Reports session/weekly limits after running in a thread (not persisted across restarts). - Pure API-key accounts generally do not report subscription limits. diff --git a/packages/provider-cursor/src/server/usageLimits.test.ts b/packages/provider-cursor/src/server/usageLimits.test.ts index e969106812e6e..9fc32f4878105 100644 --- a/packages/provider-cursor/src/server/usageLimits.test.ts +++ b/packages/provider-cursor/src/server/usageLimits.test.ts @@ -7,7 +7,7 @@ import { cursorUsageResponseToLimits, readCursorUsageLimits } from "./usageLimit describe("Cursor usage limits", () => { const checkedAt = "2026-09-16T00:00:00.000Z"; - it("uses the advertised percentages and billing-cycle reset", () => { + it("uses the advertised percentages and reset, or Spend when no allowance is included", () => { const limits = cursorUsageResponseToLimits( { billingCycleEnd: "1789876386000", @@ -40,6 +40,68 @@ describe("Cursor usage limits", () => { }, ]), ); + const withSpendLimit = cursorUsageResponseToLimits( + { + billingCycleEnd: "1789876386000", + planUsage: { totalPercentUsed: 72.4, autoPercentUsed: 69.5, apiPercentUsed: 100 }, + spendLimitUsage: { individualLimit: 5000, individualUsed: 100 }, + }, + checkedAt, + ); + expect(withSpendLimit.windows).toEqual(limits.windows); + const zeroPercents = { totalPercentUsed: 0, autoPercentUsed: 0, apiPercentUsed: 0 }; + const zeroPlanWindows = [ + { id: "apiPercentUsed", kind: "monthly", label: "Other Models", usedPercent: 0 }, + { id: "autoPercentUsed", kind: "monthly", label: "Cursor Models", usedPercent: 0 }, + { id: "totalPercentUsed", kind: "monthly", label: "Overall", usedPercent: 0 }, + ]; + const windowIds = (response: Parameters[0]) => + cursorUsageResponseToLimits(response, checkedAt).windows.map((window) => window.id); + // Usage already counted against a pooled plan keeps the plan bars. + expect( + windowIds({ + planUsage: { totalPercentUsed: 6, autoPercentUsed: 6, apiPercentUsed: 0 }, + spendLimitUsage: { pooledLimit: "3000000", overallLimit: 50000, overallUsed: 3211 }, + }), + ).toEqual(["apiPercentUsed", "autoPercentUsed", "totalPercentUsed"]); + // Fresh-cycle Pro: an included allowance, or no pool marker, keeps the plan bars. + for (const response of [ + { + planUsage: { ...zeroPercents, limit: "2000" }, + spendLimitUsage: { individualLimit: 5000, individualUsed: 0, pooledLimit: "3000000" }, + }, + { planUsage: zeroPercents, spendLimitUsage: { individualLimit: 5000 } }, + ]) { + expect(cursorUsageResponseToLimits(response, checkedAt).windows).toEqual(zeroPlanWindows); + } + expect( + windowIds({ + planUsage: { ...zeroPercents, limit: "0" }, + spendLimitUsage: { pooledLimit: "3000000", overallLimit: 50000, overallUsed: 3211 }, + }), + ).toEqual(["spendLimit"]); + // Without includePooledUsage, Cursor reports start = end = now instead of the cycle. + expect( + cursorUsageResponseToLimits( + { + billingCycleStart: "1793491200000", + billingCycleEnd: "1793491200000", + spendLimitUsage: { individualLimit: "2000", individualUsed: "500" }, + }, + checkedAt, + ).windows, + ).toEqual([{ id: "spendLimit", kind: "monthly", label: "Spend", usedPercent: 25 }]); + // Limit and used come from the same pair; protobuf JSON omits a zero used. + for (const [spendLimitUsage, usedPercent] of [ + [{ overallLimit: 50000, individualUsed: 3211 }, 0], + [{ overallLimit: 0, individualLimit: "2000", individualUsed: "500" }, 25], + ] as const) { + expect( + cursorUsageResponseToLimits({ spendLimitUsage }, checkedAt).windows.map( + (window) => window.usedPercent, + ), + ).toEqual([usedPercent]); + } }); it("reports the billing-cycle length so pace can be computed", () => { @@ -54,7 +116,7 @@ describe("Cursor usage limits", () => { }); it("omits the cycle length when the start is missing or invalid", () => { - for (const billingCycleStart of [undefined, "", "0", "not-a-number", "1796637847072"]) { + for (const billingCycleStart of [undefined, "", "0", "not-a-number"]) { expect( cursorUsageResponseToLimits( { @@ -91,9 +153,33 @@ describe("Cursor usage limits", () => { }); it("does not invent unused allowance for absent buckets", () => { - expect(cursorUsageResponseToLimits({ planUsage: {} }, checkedAt).unavailable?.reason).toBe( - "unsupported", + const linkOnly = { + checkedAt, + windows: [], + unavailable: { + reason: "unsupported", + message: + "Cursor doesn't report a personal spend limit for this account. Open Cursor's dashboard with the same account to see its usage.", + }, + externalUsage: { label: "Cursor usage", url: "https://cursor.com/dashboard?tab=usage" }, + }; + expect(cursorUsageResponseToLimits({ planUsage: {} }, checkedAt)).toEqual(linkOnly); + // Real Enterprise (token-based contract) response: no planUsage at all. + expect(cursorUsageResponseToLimits({ billingCycleEnd: "1793495876373" }, checkedAt)).toEqual( + linkOnly, ); + // Enterprise seat with only the team pool: zeroed percentages and no personal limit. + expect( + cursorUsageResponseToLimits( + { + billingCycleStart: "1793491200000", + billingCycleEnd: "1796083200000", + planUsage: { totalPercentUsed: 0, autoPercentUsed: 0, apiPercentUsed: 0 }, + spendLimitUsage: { pooledLimit: "3000000" }, + }, + checkedAt, + ), + ).toEqual(linkOnly); expect( cursorUsageResponseToLimits({ planUsage: { totalPercentUsed: 0 } }, checkedAt).windows, ).toEqual([{ id: "totalPercentUsed", kind: "monthly", label: "Overall", usedPercent: 0 }]); @@ -102,6 +188,59 @@ describe("Cursor usage limits", () => { ).toEqual([{ id: "totalPercentUsed", kind: "monthly", label: "Overall", usedPercent: 100 }]); }); + it.effect( + "requests pooled usage and shows Enterprise spend against the personal spend limit", + () => + Effect.gen(function* () { + const limits = yield* readCursorUsageLimits( + { apiEndpoint: "" }, + { CURSOR_AUTH_TOKEN: "token" }, + ).pipe( + Effect.provideService( + HttpClient.HttpClient, + HttpClient.make((request) => { + expect( + request.body._tag === "Uint8Array" && new TextDecoder().decode(request.body.body), + ).toBe('{"includePooledUsage":true}'); + return Effect.succeed( + HttpClientResponse.fromWeb( + request, + Response.json({ + billingCycleStart: "1793491200000", + billingCycleEnd: "1796083200000", + displayThreshold: 50, + planUsage: { totalPercentUsed: 0, autoPercentUsed: 0, apiPercentUsed: 0 }, + spendLimitUsage: { + limitType: "team", + overallLimit: 50000, + overallUsed: 3211, + overallRemaining: 46789, + pooledLimit: "3000000", + pooledUsed: 0, + pooledRemaining: "3000000", + }, + displayMessage: "You've used 6% of your included usage", + }), + ), + ); + }), + ), + ); + expect(limits).toEqual({ + checkedAt: expect.any(String), + windows: [ + { + id: "spendLimit", + kind: "monthly", + label: "Spend", + usedPercent: 6.422, + resetsAt: "2026-12-01T00:00:00.000Z", + }, + ], + }); + }), + ); + it.effect("requires explicit credentials and accepts an auth token", () => Effect.gen(function* () { for (const token of [undefined, "explicit-token"]) { diff --git a/packages/provider-cursor/src/server/usageLimits.ts b/packages/provider-cursor/src/server/usageLimits.ts index 48ab708554206..72c671ff98340 100644 --- a/packages/provider-cursor/src/server/usageLimits.ts +++ b/packages/provider-cursor/src/server/usageLimits.ts @@ -15,37 +15,69 @@ import { } from "@t3tools/provider-core/server/usageLimits"; import { DEFAULT_CURSOR_API_ENDPOINT, exchangeCursorApiKey } from "./apiKey.ts"; +const NO_LIMITS_MESSAGE = + "Cursor doesn't report a personal spend limit for this account. Open Cursor's dashboard with the same account to see its usage."; +const CursorInt64 = Schema.Union([Schema.String, Schema.Number]); const CursorUsageResponse = Schema.Struct({ - billingCycleStart: Schema.optional(Schema.Union([Schema.String, Schema.Number])), - billingCycleEnd: Schema.optional(Schema.Union([Schema.String, Schema.Number])), + billingCycleStart: Schema.optional(CursorInt64), + billingCycleEnd: Schema.optional(CursorInt64), planUsage: Schema.optional( Schema.Struct({ + limit: Schema.optional(CursorInt64), totalPercentUsed: Schema.optional(Schema.Number), autoPercentUsed: Schema.optional(Schema.Number), apiPercentUsed: Schema.optional(Schema.Number), }), ), + spendLimitUsage: Schema.optional( + Schema.Struct({ + overallLimit: Schema.optional(CursorInt64), + overallUsed: Schema.optional(CursorInt64), + individualLimit: Schema.optional(CursorInt64), + individualUsed: Schema.optional(CursorInt64), + pooledLimit: Schema.optional(CursorInt64), + }), + ), }); -/** Cursor's dashboard percentages include bonus usage; spend / limit does not. */ +function spendPair( + limit: typeof CursorInt64.Type | undefined, + used: typeof CursorInt64.Type | undefined, +) { + const cents = Number(limit); + return Number.isFinite(cents) && cents > 0 + ? { limit: cents, used: Number(used ?? 0) } + : undefined; +} + +/** Plan bars use Cursor's own percentages; the Spend bar is computed from cents. */ export function cursorUsageResponseToLimits( response: typeof CursorUsageResponse.Type, checkedAt: string, ) { - const reset = DateTime.make(Number(response.billingCycleEnd)); + const end = Number(response.billingCycleEnd); + const cycleStart = Number(response.billingCycleStart); + const reset = DateTime.make(end); + // Without includePooledUsage, Cursor reports start = end = now instead of the cycle. const resetsAt = - Number(response.billingCycleEnd) > 0 && Option.isSome(reset) + end > 0 && !(cycleStart >= end) && Option.isSome(reset) ? DateTime.formatIso(reset.value) : undefined; - const cycleStart = Number(response.billingCycleStart); + const { planUsage, spendLimitUsage: spend } = response; + // Enterprise sends a team pool and zeroed percentages without an included allowance. + const usageBased = + spend?.pooledLimit !== undefined && + !(Number(planUsage?.limit) > 0) && + !planUsage?.totalPercentUsed && + !planUsage?.autoPercentUsed && + !planUsage?.apiPercentUsed; const windowDurationMins = - resetsAt && cycleStart > 0 - ? Math.round((Number(response.billingCycleEnd) - cycleStart) / 60_000) - : 0; + resetsAt && cycleStart > 0 ? Math.round((end - cycleStart) / 60_000) : 0; const windows: ServerProviderUsageWindow[] = []; - if (response.planUsage) { + if (planUsage && !usageBased) { for (const { id, label } of CURSOR_USAGE_WINDOWS) { - const usedPercent = response.planUsage[id]; + if (id === "spendLimit") continue; + const usedPercent = planUsage[id]; if (usedPercent === undefined || !Number.isFinite(usedPercent)) continue; windows.push({ id, @@ -57,9 +89,23 @@ export function cursorUsageResponseToLimits( }); } } - return windows.length > 0 - ? makeUsageLimits({ checkedAt, windows }) - : makeUnavailableUsageLimits({ checkedAt, reason: "unsupported" }); + const personal = + spendPair(spend?.overallLimit, spend?.overallUsed) ?? + spendPair(spend?.individualLimit, spend?.individualUsed); + if (windows.length === 0 && personal && Number.isFinite(personal.used)) { + windows.push({ + id: "spendLimit", + kind: "monthly", + label: "Spend", + usedPercent: clampPercent((personal.used / personal.limit) * 100), + ...(resetsAt ? { resetsAt } : {}), + }); + } + if (windows.length > 0) return makeUsageLimits({ checkedAt, windows }); + return { + ...makeUnavailableUsageLimits({ checkedAt, reason: "unsupported", message: NO_LIMITS_MESSAGE }), + externalUsage: { label: "Cursor usage", url: "https://cursor.com/dashboard?tab=usage" }, + }; } export const readCursorUsageLimits = Effect.fn("readCursorUsageLimits")(function* ( @@ -94,7 +140,7 @@ export const readCursorUsageLimits = Effect.fn("readCursorUsageLimits")(function "connect-protocol-version": "1", "x-cursor-client-type": "cli", }), - HttpClientRequest.bodyJsonUnsafe({}), + HttpClientRequest.bodyJsonUnsafe({ includePooledUsage: true }), ), ); const body = yield* HttpClientResponse.schemaBodyJson(CursorUsageResponse)( diff --git a/packages/shared/src/usageLimits.test.ts b/packages/shared/src/usageLimits.test.ts index c2ef9dccc8c97..17b07065c7f8f 100644 --- a/packages/shared/src/usageLimits.test.ts +++ b/packages/shared/src/usageLimits.test.ts @@ -131,6 +131,7 @@ describe("new thread model fallback", () => { ["cursor", ["autoPercentUsed"], "claude-opus-5-5", false, undefined, undefined], ["cursor", ["autoPercentUsed"], "composer-2.5", false, undefined, undefined], ["cursor", ["autoPercentUsed", "apiPercentUsed"], "composer-2.5", true, undefined, undefined], + ["cursor", ["spendLimit"], "composer-2.5", true, undefined, undefined], ["codex", ["individual"], "gpt-5.5", true, undefined, undefined], ["opencode", ["go_weekly"], "opencode/big-pickle", false, undefined, undefined], ["opencode", ["go_weekly"], "opencode-go/big-pickle", true, undefined, undefined], diff --git a/packages/shared/src/usageLimits.ts b/packages/shared/src/usageLimits.ts index 765d7dbca3b4e..db86524d7ddad 100644 --- a/packages/shared/src/usageLimits.ts +++ b/packages/shared/src/usageLimits.ts @@ -44,6 +44,8 @@ export function exhaustedUsageWindow( if (model === undefined) return exhausted[0]; switch (provider?.driver) { case "cursor": { + const spend = exhausted.find((window) => window.id === "spendLimit"); + if (spend) return spend; const api = exhausted.find((window) => window.id === "apiPercentUsed"); const auto = exhausted.find((window) => window.id === "autoPercentUsed"); return /^(auto|default|grok|composer)/.test(model) ? auto && api : api; @@ -132,6 +134,11 @@ export const CURSOR_USAGE_WINDOWS = [ label: "Other Models", description: "Usage allowance for third-party models such as Claude, GPT, and Gemini.", }, + { + id: "spendLimit", + label: "Spend", + description: "Spending this billing cycle against your Cursor spend limit.", + }, ] as const; export function cursorUsageWindowDetails(id: string, pool: LimitPool) { diff --git a/packages/shared/src/usageLimitsCopy.ts b/packages/shared/src/usageLimitsCopy.ts index e8f02ef9a11eb..70f7b2ee885a3 100644 --- a/packages/shared/src/usageLimitsCopy.ts +++ b/packages/shared/src/usageLimitsCopy.ts @@ -37,6 +37,12 @@ const CURSOR_USAGE_WINDOW_COPY: Readonly< label: msg("Other Models"), description: msg("Usage allowance for third-party models such as Claude, GPT, and Gemini."), }, + spendLimit: { + label: msg("Spend"), + description: msg("Spending this billing cycle against your {provider} spend limit.", { + provider: "Cursor", + }), + }, }; /** @public */