diff --git a/apps/mobile/src/i18n/translations/de.json b/apps/mobile/src/i18n/translations/de.json index 1116dd8895c6e..6635c19f7caca 100644 --- a/apps/mobile/src/i18n/translations/de.json +++ b/apps/mobile/src/i18n/translations/de.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer und Auto nutzen dieses Kontingent.", "d2becdc27390c92c": "Andere Modelle", "3abbefc7732635ff": "Nutzungskontingent für Modelle von Drittanbietern wie Claude, GPT und Gemini.", + "c7566c908e14be09": "Ausgaben", + "ae693772acb75c75": "Ausgaben in diesem Abrechnungszeitraum im Verhältnis zu deinem {provider}-Ausgabenlimit.", "7d72af75b2812d60": "{provider} auf {environment}", "bb34eaf6ddc55a72": "Dieses Konto hat keine Abonnementlimits.", "42a2622893a6bced": "Limits konnten nicht gelesen werden.", diff --git a/apps/mobile/src/i18n/translations/en.json b/apps/mobile/src/i18n/translations/en.json index d9c7d08df765b..6793b9f6c0cbe 100644 --- a/apps/mobile/src/i18n/translations/en.json +++ b/apps/mobile/src/i18n/translations/en.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer, and Auto use this allowance.", "d2becdc27390c92c": "Other Models", "3abbefc7732635ff": "Usage allowance for third-party models such as Claude, GPT, and Gemini.", + "c7566c908e14be09": "Spend", + "ae693772acb75c75": "Spending this billing cycle against your {provider} spend limit.", "7d72af75b2812d60": "{provider} on {environment}", "bb34eaf6ddc55a72": "This account has no subscription limits.", "42a2622893a6bced": "Could not read limits.", diff --git a/apps/mobile/src/i18n/translations/es.json b/apps/mobile/src/i18n/translations/es.json index 8ceac2b26a722..6b832e022879b 100644 --- a/apps/mobile/src/i18n/translations/es.json +++ b/apps/mobile/src/i18n/translations/es.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer y Auto usan esta asignación.", "d2becdc27390c92c": "Otros modelos", "3abbefc7732635ff": "Asignación de uso para modelos de terceros como Claude, GPT y Gemini.", + "c7566c908e14be09": "Gasto", + "ae693772acb75c75": "Gasto en este ciclo de facturación frente a tu límite de gasto de {provider}.", "7d72af75b2812d60": "{provider} en {environment}", "bb34eaf6ddc55a72": "Esta cuenta no tiene límites de suscripción.", "42a2622893a6bced": "No se pudieron leer los límites.", diff --git a/apps/mobile/src/i18n/translations/fr.json b/apps/mobile/src/i18n/translations/fr.json index a6904b69d7f73..b4e0deef90823 100644 --- a/apps/mobile/src/i18n/translations/fr.json +++ b/apps/mobile/src/i18n/translations/fr.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer et Auto utilisent ce quota.", "d2becdc27390c92c": "Autres modèles", "3abbefc7732635ff": "Quota d’utilisation des modèles tiers comme Claude, GPT et Gemini.", + "c7566c908e14be09": "Dépenses", + "ae693772acb75c75": "Dépenses de ce cycle de facturation par rapport à votre limite de dépenses {provider}.", "7d72af75b2812d60": "{provider} sur {environment}", "bb34eaf6ddc55a72": "Ce compte n’a pas de limites d’abonnement.", "42a2622893a6bced": "Impossible de lire les limites.", diff --git a/apps/mobile/src/i18n/translations/ja.json b/apps/mobile/src/i18n/translations/ja.json index 3ce3515fae73b..9b724e71a2a5e 100644 --- a/apps/mobile/src/i18n/translations/ja.json +++ b/apps/mobile/src/i18n/translations/ja.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok、Composer、Auto はこの使用枠を使います。", "d2becdc27390c92c": "その他のモデル", "3abbefc7732635ff": "Claude、GPT、Gemini などのサードパーティモデル用の使用枠です。", + "c7566c908e14be09": "支出", + "ae693772acb75c75": "今回の請求期間の支出と {provider} の支出上限の比較です。", "7d72af75b2812d60": "{environment} の {provider}", "bb34eaf6ddc55a72": "このアカウントにはサブスクリプションの上限がありません。", "42a2622893a6bced": "上限を読み取れませんでした。", diff --git a/apps/mobile/src/i18n/translations/ko.json b/apps/mobile/src/i18n/translations/ko.json index 484ab67231b2e..323ae84149b98 100644 --- a/apps/mobile/src/i18n/translations/ko.json +++ b/apps/mobile/src/i18n/translations/ko.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer, Auto가 이 사용량을 사용합니다.", "d2becdc27390c92c": "기타 모델", "3abbefc7732635ff": "Claude, GPT, Gemini 등 타사 모델의 사용 한도입니다.", + "c7566c908e14be09": "지출", + "ae693772acb75c75": "이번 결제 주기의 지출을 {provider} 지출 한도와 비교합니다.", "7d72af75b2812d60": "{environment}의 {provider}", "bb34eaf6ddc55a72": "이 계정에는 구독 한도가 없습니다.", "42a2622893a6bced": "한도를 읽을 수 없습니다.", diff --git a/apps/mobile/src/i18n/translations/pt-BR.json b/apps/mobile/src/i18n/translations/pt-BR.json index 4959be9c365b1..81c7326dea1be 100644 --- a/apps/mobile/src/i18n/translations/pt-BR.json +++ b/apps/mobile/src/i18n/translations/pt-BR.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer e Auto usam esta cota.", "d2becdc27390c92c": "Outros modelos", "3abbefc7732635ff": "Cota de uso para modelos de terceiros, como Claude, GPT e Gemini.", + "c7566c908e14be09": "Gastos", + "ae693772acb75c75": "Gastos neste ciclo de cobrança em relação ao seu limite de gastos do {provider}.", "7d72af75b2812d60": "{provider} em {environment}", "bb34eaf6ddc55a72": "Esta conta não tem limites de assinatura.", "42a2622893a6bced": "Não foi possível ler os limites.", diff --git a/apps/mobile/src/i18n/translations/ru.json b/apps/mobile/src/i18n/translations/ru.json index 7987d3d16485a..6a8be2edf114a 100644 --- a/apps/mobile/src/i18n/translations/ru.json +++ b/apps/mobile/src/i18n/translations/ru.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer и Auto расходуют этот лимит.", "d2becdc27390c92c": "Другие модели", "3abbefc7732635ff": "Лимит использования сторонних моделей, таких как Claude, GPT и Gemini.", + "c7566c908e14be09": "Расходы", + "ae693772acb75c75": "Расходы за этот расчётный период относительно вашего лимита расходов в {provider}.", "7d72af75b2812d60": "{provider} на {environment}", "bb34eaf6ddc55a72": "У этого аккаунта нет лимитов подписки.", "42a2622893a6bced": "Не удалось прочитать лимиты.", diff --git a/apps/mobile/src/i18n/translations/sv.json b/apps/mobile/src/i18n/translations/sv.json index 38f2f3c80172c..92a37e719c3a9 100644 --- a/apps/mobile/src/i18n/translations/sv.json +++ b/apps/mobile/src/i18n/translations/sv.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer och Auto använder den här kvoten.", "d2becdc27390c92c": "Andra modeller", "3abbefc7732635ff": "Användningskvot för tredjepartsmodeller som Claude, GPT och Gemini.", + "c7566c908e14be09": "Utgifter", + "ae693772acb75c75": "Utgifter under den här faktureringsperioden mot din utgiftsgräns i {provider}.", "7d72af75b2812d60": "{provider} på {environment}", "bb34eaf6ddc55a72": "Det här kontot har inga prenumerationsgränser.", "42a2622893a6bced": "Kunde inte läsa gränser.", diff --git a/apps/mobile/src/i18n/translations/zh.json b/apps/mobile/src/i18n/translations/zh.json index e673d0e56ba1b..133b5f9f09ad9 100644 --- a/apps/mobile/src/i18n/translations/zh.json +++ b/apps/mobile/src/i18n/translations/zh.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok、Composer 和 Auto 使用此额度。", "d2becdc27390c92c": "其他模型", "3abbefc7732635ff": "Claude、GPT 和 Gemini 等第三方模型的用量额度。", + "c7566c908e14be09": "支出", + "ae693772acb75c75": "本计费周期内的支出与你的 {provider} 支出上限对比。", "7d72af75b2812d60": "{environment} 上的 {provider}", "bb34eaf6ddc55a72": "此账户没有订阅限制。", "42a2622893a6bced": "无法读取限额。", diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json index 7900e73186091..ffadbdd2d2b19 100644 --- a/apps/web/src/i18n/translations/de.json +++ b/apps/web/src/i18n/translations/de.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer und Auto nutzen dieses Kontingent.", "d2becdc27390c92c": "Andere Modelle", "3abbefc7732635ff": "Nutzungskontingent für Modelle von Drittanbietern wie Claude, GPT und Gemini.", + "c7566c908e14be09": "Ausgaben", + "ae693772acb75c75": "Ausgaben in diesem Abrechnungszeitraum im Verhältnis zu deinem {provider}-Ausgabenlimit.", "7d72af75b2812d60": "{provider} auf {environment}", "bb34eaf6ddc55a72": "Dieses Konto hat keine Abonnementlimits.", "42a2622893a6bced": "Limits konnten nicht gelesen werden.", diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json index 5bdd7c383d319..e08ef4c240b47 100644 --- a/apps/web/src/i18n/translations/en.json +++ b/apps/web/src/i18n/translations/en.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer, and Auto use this allowance.", "d2becdc27390c92c": "Other Models", "3abbefc7732635ff": "Usage allowance for third-party models such as Claude, GPT, and Gemini.", + "c7566c908e14be09": "Spend", + "ae693772acb75c75": "Spending this billing cycle against your {provider} spend limit.", "7d72af75b2812d60": "{provider} on {environment}", "bb34eaf6ddc55a72": "This account has no subscription limits.", "42a2622893a6bced": "Could not read limits.", diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json index 91dbb2b07f50f..598ff3f606b26 100644 --- a/apps/web/src/i18n/translations/es.json +++ b/apps/web/src/i18n/translations/es.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer y Auto usan esta asignación.", "d2becdc27390c92c": "Otros modelos", "3abbefc7732635ff": "Asignación de uso para modelos de terceros como Claude, GPT y Gemini.", + "c7566c908e14be09": "Gasto", + "ae693772acb75c75": "Gasto en este ciclo de facturación frente a tu límite de gasto de {provider}.", "7d72af75b2812d60": "{provider} en {environment}", "bb34eaf6ddc55a72": "Esta cuenta no tiene límites de suscripción.", "42a2622893a6bced": "No se pudieron leer los límites.", diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json index f5cf7e62a4744..da889e783adeb 100644 --- a/apps/web/src/i18n/translations/fr.json +++ b/apps/web/src/i18n/translations/fr.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer et Auto utilisent ce quota.", "d2becdc27390c92c": "Autres modèles", "3abbefc7732635ff": "Quota d’utilisation des modèles tiers comme Claude, GPT et Gemini.", + "c7566c908e14be09": "Dépenses", + "ae693772acb75c75": "Dépenses de ce cycle de facturation par rapport à votre limite de dépenses {provider}.", "7d72af75b2812d60": "{provider} sur {environment}", "bb34eaf6ddc55a72": "Ce compte n’a pas de limites d’abonnement.", "42a2622893a6bced": "Impossible de lire les limites.", diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json index 7e3be343b068b..6ea6d972b7eb8 100644 --- a/apps/web/src/i18n/translations/ja.json +++ b/apps/web/src/i18n/translations/ja.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok、Composer、Auto はこの使用枠を使います。", "d2becdc27390c92c": "その他のモデル", "3abbefc7732635ff": "Claude、GPT、Gemini などのサードパーティモデル用の使用枠です。", + "c7566c908e14be09": "支出", + "ae693772acb75c75": "今回の請求期間の支出と {provider} の支出上限の比較です。", "7d72af75b2812d60": "{environment} の {provider}", "bb34eaf6ddc55a72": "このアカウントにはサブスクリプションの上限がありません。", "42a2622893a6bced": "上限を読み取れませんでした。", diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json index ef69858aead11..b8df058e81a85 100644 --- a/apps/web/src/i18n/translations/ko.json +++ b/apps/web/src/i18n/translations/ko.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer, Auto가 이 사용량을 사용합니다.", "d2becdc27390c92c": "기타 모델", "3abbefc7732635ff": "Claude, GPT, Gemini 등 타사 모델의 사용 한도입니다.", + "c7566c908e14be09": "지출", + "ae693772acb75c75": "이번 결제 주기의 지출을 {provider} 지출 한도와 비교합니다.", "7d72af75b2812d60": "{environment}의 {provider}", "bb34eaf6ddc55a72": "이 계정에는 구독 한도가 없습니다.", "42a2622893a6bced": "한도를 읽을 수 없습니다.", diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json index 5b2f82a27a416..b353737b36bc6 100644 --- a/apps/web/src/i18n/translations/pt-BR.json +++ b/apps/web/src/i18n/translations/pt-BR.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer e Auto usam esta cota.", "d2becdc27390c92c": "Outros modelos", "3abbefc7732635ff": "Cota de uso para modelos de terceiros, como Claude, GPT e Gemini.", + "c7566c908e14be09": "Gastos", + "ae693772acb75c75": "Gastos neste ciclo de cobrança em relação ao seu limite de gastos do {provider}.", "7d72af75b2812d60": "{provider} em {environment}", "bb34eaf6ddc55a72": "Esta conta não tem limites de assinatura.", "42a2622893a6bced": "Não foi possível ler os limites.", diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json index 2891cb8165d7c..42d06d6458b6f 100644 --- a/apps/web/src/i18n/translations/ru.json +++ b/apps/web/src/i18n/translations/ru.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer и Auto расходуют этот лимит.", "d2becdc27390c92c": "Другие модели", "3abbefc7732635ff": "Лимит использования сторонних моделей, таких как Claude, GPT и Gemini.", + "c7566c908e14be09": "Расходы", + "ae693772acb75c75": "Расходы за этот расчётный период относительно вашего лимита расходов в {provider}.", "7d72af75b2812d60": "{provider} на {environment}", "bb34eaf6ddc55a72": "У этого аккаунта нет лимитов подписки.", "42a2622893a6bced": "Не удалось прочитать лимиты.", diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json index c792d6fb4a981..6c8a50de89dad 100644 --- a/apps/web/src/i18n/translations/sv.json +++ b/apps/web/src/i18n/translations/sv.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok, Composer och Auto använder den här kvoten.", "d2becdc27390c92c": "Andra modeller", "3abbefc7732635ff": "Användningskvot för tredjepartsmodeller som Claude, GPT och Gemini.", + "c7566c908e14be09": "Utgifter", + "ae693772acb75c75": "Utgifter under den här faktureringsperioden mot din utgiftsgräns i {provider}.", "7d72af75b2812d60": "{provider} på {environment}", "bb34eaf6ddc55a72": "Det här kontot har inga prenumerationsgränser.", "42a2622893a6bced": "Kunde inte läsa gränser.", diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json index cd80e9a35102a..b76eedd3ddeda 100644 --- a/apps/web/src/i18n/translations/zh.json +++ b/apps/web/src/i18n/translations/zh.json @@ -1307,6 +1307,8 @@ "23eed587f1bef1a6": "Grok、Composer 和 Auto 使用此额度。", "d2becdc27390c92c": "其他模型", "3abbefc7732635ff": "Claude、GPT 和 Gemini 等第三方模型的用量额度。", + "c7566c908e14be09": "支出", + "ae693772acb75c75": "本计费周期内的支出与你的 {provider} 支出上限对比。", "7d72af75b2812d60": "{environment} 上的 {provider}", "bb34eaf6ddc55a72": "此账户没有订阅限制。", "42a2622893a6bced": "无法读取限额。", diff --git a/docs/user/usage.md b/docs/user/usage.md index 43f4c94a19328..afabba3ee7f56 100644 --- a/docs/user/usage.md +++ b/docs/user/usage.md @@ -166,7 +166,9 @@ refresh provider status. Cursor reports its monthly allowance, including separate Auto and API usage, for `CURSOR_AUTH_TOKEN` when it is set, otherwise for the account you signed in with in T3 or set as `CURSOR_API_KEY`. Sign-in and API keys report limits only with Cursor's default API endpoint. If you configure a custom -Cursor endpoint, use an explicit `CURSOR_AUTH_TOKEN` for limits. +Cursor endpoint, use an explicit `CURSOR_AUTH_TOKEN` for limits. Accounts without a monthly +allowance, such as Enterprise, show a **Spend** bar for this billing cycle against your personal +spend limit. If Cursor reports no personal limit, Usage links to Cursor's usage dashboard instead. Grok reports the remaining subscription allowance and reset time for its current billing period after signing in with `grok login`. Explicit `XAI_API_KEY` connections and custom authentication diff --git a/packages/provider-cursor/src/server/usageLimits.test.ts b/packages/provider-cursor/src/server/usageLimits.test.ts index e969106812e6e..3e2d15b7c3d91 100644 --- a/packages/provider-cursor/src/server/usageLimits.test.ts +++ b/packages/provider-cursor/src/server/usageLimits.test.ts @@ -42,6 +42,41 @@ describe("Cursor usage limits", () => { ); }); + it("shows Spend against the personal limit only when no allowance is included", () => { + const zeroPercents = { totalPercentUsed: 0, autoPercentUsed: 0, apiPercentUsed: 0 }; + const windowIds = (response: Parameters[0]) => + cursorUsageResponseToLimits(response, checkedAt).windows.map((window) => window.id); + const planIds = ["apiPercentUsed", "autoPercentUsed", "totalPercentUsed"]; + const pool = { pooledLimit: "3000000", overallLimit: 50000, overallUsed: 3211 }; + // Usage already counted against the plan, an included allowance, or no team pool keep the plan bars. + expect( + windowIds({ planUsage: { ...zeroPercents, autoPercentUsed: 6 }, spendLimitUsage: pool }), + ).toEqual(planIds); + expect( + windowIds({ planUsage: { ...zeroPercents, limit: "2000" }, spendLimitUsage: pool }), + ).toEqual(planIds); + expect( + windowIds({ planUsage: zeroPercents, spendLimitUsage: { individualLimit: 5000 } }), + ).toEqual(planIds); + // A start equal to the end is not a billing cycle; a missing used means zero. + expect( + cursorUsageResponseToLimits( + { + billingCycleStart: "1793491200000", + billingCycleEnd: "1793491200000", + spendLimitUsage: { overallLimit: 0, individualLimit: "2000", individualUsed: "500" }, + }, + checkedAt, + ).windows, + ).toEqual([{ id: "spendLimit", kind: "monthly", label: "Spend", usedPercent: 25 }]); + expect( + cursorUsageResponseToLimits( + { spendLimitUsage: { overallLimit: 50000, individualUsed: 3211 } }, + checkedAt, + ).windows[0]?.usedPercent, + ).toBe(0); + }); + it("reports the billing-cycle length so pace can be computed", () => { const planUsage = { totalPercentUsed: 40, autoPercentUsed: 30, apiPercentUsed: 20 }; const durations = (billingCycleStart: string | number | undefined, billingCycleEnd: string) => @@ -54,7 +89,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 +126,27 @@ 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); + // Enterprise seat with only the team pool and no personal limit. + expect( + cursorUsageResponseToLimits( + { + 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 +155,61 @@ 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, + // Captured from a live Enterprise account (token-based contract), 2026-11-23: + // the team pool arrives as int64 strings, the personal pair as numbers. + Response.json({ + billingCycleStart: "1793491200000", + billingCycleEnd: "1796083200000", + planUsage: { totalPercentUsed: 0, autoPercentUsed: 0, apiPercentUsed: 0 }, + spendLimitUsage: { + totalSpend: 679881371, + pooledLimit: "1009395000", + pooledUsed: 679881371, + pooledRemaining: "329513629", + limitType: "team", + overallLimit: 100000, + overallUsed: 68757, + overallRemaining: 31243, + }, + }), + ), + ); + }), + ), + ); + expect(limits).toEqual({ + checkedAt: expect.any(String), + windows: [ + { + id: "spendLimit", + kind: "monthly", + label: "Spend", + usedPercent: 68.757, + resetsAt: "2026-12-01T00:00:00.000Z", + windowDurationMins: 43_200, + }, + ], + }); + }), + ); + 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..5222a9a95f0c4 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,24 @@ 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 } : {}), + ...(windowDurationMins > 0 ? { windowDurationMins } : {}), + }); + } + 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 +141,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 0019c74e1d5cd..ac6e23bcec569 100644 --- a/packages/shared/src/usageLimits.test.ts +++ b/packages/shared/src/usageLimits.test.ts @@ -130,6 +130,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], ["antigravity", ["gemini-weekly"], "claude-opus-5-5", false, undefined, undefined], ["antigravity", ["3p-weekly"], "claude-opus-5-5", true, undefined, undefined], ["antigravity", ["gemini-weekly"], "antigravity-default", true, undefined, undefined], diff --git a/packages/shared/src/usageLimits.ts b/packages/shared/src/usageLimits.ts index 711f3637d0a9f..d25ebb4cce928 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; @@ -144,6 +146,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 85f78e0f11f28..539db722cd880 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 */