cursor 0.2.6: an account that may spend on-demand is not used up when its included usage is (fottencity on Discord)
A Cursor team (or personal plan) with on-demand spend allowed keeps being served once Cursor Models / Other Models reach 100% of the included usage. The usage read gave only those pools, so magpie counted the account used up: smart routing put it last, and any failure while a pool read 100% rested it until the billing period renewed (held to 8 days). usage now also reads GetHardLimit and the period's spendLimitUsage, and derives the On-demand state exactly as cursor-agent 2026.10.01's usage view does (fixed limit, unlimited, disabled, unavailable). When on-demand is fixed or unlimited, the pools are still shown but marked aside, and an On-demand window ($used / $limit) is the allowance: used up at its limit, never when there is none (then aside too). Disabled or not known: the pools are the allowance, as before. Bot stays before Total. Verified: bun test (77 pass); the three new on-demand tests fail on the old index.mjs (pools not aside, no On-demand window); bun scripts/check.mjs cursor. Fixture shapes come from cursor-agent's own protobuf schema (GetCurrentPeriodUsageResponse.SpendLimitUsage, GetHardLimitResponse); not tried against a real enterprise account.
This commit is contained in:
@@ -131,6 +131,13 @@ Accounts with a Grok Bot allowance also show its usage and reset time;
|
||||
active trials are labelled separately. A spent Bot allowance doesn't stop
|
||||
Cursor requests.
|
||||
|
||||
An account that may spend on-demand once its included usage is gone (a
|
||||
team or personal spend limit, as `cursor-agent`'s usage view shows it) also
|
||||
shows On-demand: its spend, and its limit when it has one. Cursor keeps
|
||||
serving such an account past the included usage, so magpie doesn't count
|
||||
it used up when Cursor Models or Other Models reach 100%; it does when the
|
||||
on-demand spend reaches its limit.
|
||||
|
||||
Sign in to the Cursor account linked in Grok Bot. A linked SuperGrok
|
||||
subscription grants Bot access without a paid Cursor plan; see
|
||||
[Grok Bot plans and billing](https://cursor.com/help/grok-bot/plans).
|
||||
|
||||
+71
-11
@@ -380,16 +380,67 @@ function firstParty(model) {
|
||||
return ["grok-4.5", "grok-4.6", "grok-4.7"].some((b) => model === b || model.startsWith(b + "-"))
|
||||
}
|
||||
|
||||
// onDemandOf is what Cursor still serves once the included usage is spent,
|
||||
// as cursor-agent's own usage view tells it (its On-demand line): from the
|
||||
// period's spendLimitUsage (cents) and, where that sets no limit of the
|
||||
// user's, GetHardLimit's reply (dollars; undefined when it couldn't be
|
||||
// read). kind is "fixed" (up to limitDollars), "unlimited", "disabled" or
|
||||
// "unavailable" (not known).
|
||||
function onDemandOf(data, hard) {
|
||||
const s = data?.spendLimitUsage
|
||||
const usedDollars = Number(s?.individualUsed ?? 0) / 100
|
||||
const own =
|
||||
s?.individualLimit === undefined
|
||||
? undefined
|
||||
: Number(s.individualLimit) > 0
|
||||
? { kind: "fixed", usedDollars, limitDollars: Number(s.individualLimit) / 100 }
|
||||
: { kind: "disabled", usedDollars }
|
||||
if (s?.limitType === "team") {
|
||||
if (own) return own
|
||||
if (hard) return hard.noUsageBasedAllowed || !(Number(hard.hardLimit) > 0) ? { kind: "disabled", usedDollars } : { kind: "unlimited", usedDollars }
|
||||
return Number(s.pooledLimit ?? 0) > 0 ? { kind: "unlimited", usedDollars } : { kind: "unavailable", usedDollars }
|
||||
}
|
||||
if (!hard) return own ?? { kind: "unavailable", usedDollars }
|
||||
if (hard.noUsageBasedAllowed) return { kind: "disabled", usedDollars }
|
||||
const limit = Number(hard.hardLimit ?? 0)
|
||||
if (limit >= 2147483647) return { kind: "unlimited", usedDollars }
|
||||
return limit > 0 ? { kind: "fixed", usedDollars, limitDollars: limit } : { kind: "disabled", usedDollars }
|
||||
}
|
||||
|
||||
// hardLimit is GetHardLimit's reply, undefined when it couldn't be read.
|
||||
async function hardLimit(tok) {
|
||||
try {
|
||||
const res = await fetch(API + "/aiserver.v1.DashboardService/GetHardLimit", {
|
||||
method: "POST",
|
||||
headers: { Authorization: `Bearer ${tok}`, "Content-Type": "application/json", "Connect-Protocol-Version": "1" },
|
||||
body: "{}",
|
||||
signal: AbortSignal.timeout(15_000),
|
||||
})
|
||||
return res.ok ? ((await res.json()) ?? undefined) : undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
const dollars = (n) => "$" + n.toFixed(2)
|
||||
|
||||
// usage is the account's windows this billing period; an enterprise plan
|
||||
// reports spend instead, and gets none. ids are the models it can be
|
||||
// asked for, each counted by the pool Cursor bills it to.
|
||||
// asked for, each counted by the pool Cursor bills it to. An account that
|
||||
// may spend on-demand once its included usage is gone (fottencity on
|
||||
// Discord: a team that pays for more) is still served when the pools are
|
||||
// spent, so they are shown aside, and its On-demand spend is what can run
|
||||
// out: at its limit, or never when it has none.
|
||||
async function usage(tok, ids) {
|
||||
const res = await fetch(API + "/aiserver.v1.DashboardService/GetCurrentPeriodUsage", {
|
||||
method: "POST",
|
||||
headers: { Authorization: `Bearer ${tok}`, "Content-Type": "application/json", "Connect-Protocol-Version": "1" },
|
||||
body: "{}",
|
||||
signal: AbortSignal.timeout(15_000),
|
||||
})
|
||||
const [res, hard] = await Promise.all([
|
||||
fetch(API + "/aiserver.v1.DashboardService/GetCurrentPeriodUsage", {
|
||||
method: "POST",
|
||||
headers: { Authorization: `Bearer ${tok}`, "Content-Type": "application/json", "Connect-Protocol-Version": "1" },
|
||||
body: "{}",
|
||||
signal: AbortSignal.timeout(15_000),
|
||||
}),
|
||||
hardLimit(tok),
|
||||
])
|
||||
if (!res.ok) return { error: statusText(res.status), windows: [] }
|
||||
const data = await res.json()
|
||||
const u = data?.planUsage
|
||||
@@ -412,11 +463,20 @@ async function usage(tok, ids) {
|
||||
const asked = ids.flatMap((id) => [id, id.replace(/@[^@]*$/, "")])
|
||||
const pool = [...new Set(["auto", ...asked, ...(data.autoBucketModels ?? [])])].filter(inPool)
|
||||
const num = (v) => (typeof v === "number" ? v : 0)
|
||||
const od = onDemandOf(data, hard)
|
||||
const pooled = od.kind === "fixed" || od.kind === "unlimited" ? { aside: true } : {}
|
||||
const onDemand =
|
||||
od.kind === "fixed"
|
||||
? [{ name: "On-demand", used: Math.max(0, Math.min(100, (100 * od.usedDollars) / od.limitDollars)), display: `${dollars(od.usedDollars)} / ${dollars(od.limitDollars)}`, ...resets }]
|
||||
: od.kind === "unlimited"
|
||||
? [{ name: "On-demand", used: 0, display: dollars(od.usedDollars), ...resets, aside: true }]
|
||||
: []
|
||||
// the two pools fit the line; the total goes in its tooltip
|
||||
return {
|
||||
windows: [
|
||||
{ name: "Cursor Models", used: num(u.autoPercentUsed), ...resets, models: pool },
|
||||
{ name: "Other Models", used: num(u.apiPercentUsed), ...resets, notModels: pool },
|
||||
{ name: "Cursor Models", used: num(u.autoPercentUsed), ...resets, models: pool, ...pooled },
|
||||
{ name: "Other Models", used: num(u.apiPercentUsed), ...resets, notModels: pool, ...pooled },
|
||||
...onDemand,
|
||||
{ name: "Total", used: num(u.totalPercentUsed), ...resets, aside: true },
|
||||
],
|
||||
}
|
||||
@@ -2197,7 +2257,7 @@ export async function CursorAuthPlugin() {
|
||||
}
|
||||
const [u, plan, bot] = await Promise.all([usage(tok, Object.keys(provider?.models ?? {})), planOf(tok), botUsage(tok)])
|
||||
// Put Bot before Total for magpie's three menu-bar rings.
|
||||
const windows = [...u.windows.filter((w) => !w.aside), ...bot, ...u.windows.filter((w) => w.aside)]
|
||||
const windows = [...u.windows.filter((w) => w.name !== "Total"), ...bot, ...u.windows.filter((w) => w.name === "Total")]
|
||||
return { ...u, windows, ...(plan ? { plan } : {}), signIn: "kept" }
|
||||
},
|
||||
},
|
||||
@@ -2240,4 +2300,4 @@ export async function CursorAuthPlugin() {
|
||||
}
|
||||
|
||||
// for tests
|
||||
export const _internal = { resetH1: () => (h1Until = 0), onH1: () => Date.now() < h1Until, H2, H1, h2Blocked, open, openH1, STEP_WAIT, stepUsage, ledger, owed, flights, misses, unreadable, catalog, usable, request, modelsOf, tokensOf, maxRequired, conversationID, usageOf, sessionOf, SESSION, errorResponse, kept, poolBase, conversation, buildRun, decode, exec, fields, pb, pbValue, pbAny, frame, frames, failure, toolsOf, expiry }
|
||||
export const _internal = { onDemandOf,resetH1: () => (h1Until = 0), onH1: () => Date.now() < h1Until, H2, H1, h2Blocked, open, openH1, STEP_WAIT, stepUsage, ledger, owed, flights, misses, unreadable, catalog, usable, request, modelsOf, tokensOf, maxRequired, conversationID, usageOf, sessionOf, SESSION, errorResponse, kept, poolBase, conversation, buildRun, decode, exec, fields, pb, pbValue, pbAny, frame, frames, failure, toolsOf, expiry }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-cursor-auth",
|
||||
"version": "0.2.5",
|
||||
"version": "0.2.6",
|
||||
"description": "Cursor subscriptions (Pro, Pro+, Ultra, Teams) in OpenCode and magpie, through the API cursor-agent talks to",
|
||||
"type": "module",
|
||||
"main": "./index.mjs",
|
||||
|
||||
@@ -80,7 +80,7 @@ test("the card names the plan as cursor-agent about does (GetPlanInfo's planName
|
||||
expect(plan.headers.Authorization).toBe(`Bearer ${a.access}`)
|
||||
const again = await run(a, reply)
|
||||
expect(again.u.plan).toBe("Pro+")
|
||||
expect(again.seen.map((r) => r.url)).toEqual([PERIOD])
|
||||
expect(again.seen.map((r) => r.url)).not.toContain(PLAN)
|
||||
})
|
||||
|
||||
test("a plan Cursor doesn't say leaves the card's plan out", async () => {
|
||||
@@ -214,3 +214,79 @@ test("Bot login redirects are refused", async () => {
|
||||
expect(u).toEqual(normal)
|
||||
expect(seen.find((r) => r.url === BOT)).toMatchObject({ redirect: "error" })
|
||||
})
|
||||
|
||||
// fottencity on Discord: a team that pays for on-demand usage once the
|
||||
// included usage is gone. Cursor goes on serving it, so the spent pools must
|
||||
// not read as the account used up; its on-demand spend is what runs out.
|
||||
// The replies are GetCurrentPeriodUsage's and GetHardLimit's as
|
||||
// cursor-agent 2026.10.01 decodes them (Connect JSON of
|
||||
// GetCurrentPeriodUsageResponse.SpendLimitUsage: cents, pooled_limit an
|
||||
// int64 string; GetHardLimitResponse: dollars), and its usage view's
|
||||
// On-demand line is what is read from them.
|
||||
const HARD = "https://api2.cursor.sh/aiserver.v1.DashboardService/GetHardLimit"
|
||||
const spent = { billingCycleEnd: "1792833042000", planUsage: { autoPercentUsed: 100, apiPercentUsed: 100, totalPercentUsed: 100 } }
|
||||
const at = new Date(1792833042000).toISOString()
|
||||
const onDemand = (period, hard) =>
|
||||
run(fresh(), (url) => {
|
||||
if (url === PLAN) return Response.json({})
|
||||
if (url === HARD) return hard instanceof Response ? hard : Response.json(hard)
|
||||
return Response.json(period)
|
||||
})
|
||||
const shape = (u) => u.windows.map(({ models, notModels, ...w }) => w)
|
||||
|
||||
test("a team member's own on-demand limit: the spent pools are aside, the on-demand spend is the allowance", async () => {
|
||||
const { u, seen } = await onDemand({ ...spent, spendLimitUsage: { totalSpend: 52000, individualLimit: 50000, individualUsed: 12345, individualRemaining: 37655, limitType: "team", pooledLimit: "0" } }, {})
|
||||
expect(shape(u)).toEqual([
|
||||
{ name: "Cursor Models", used: 100, resetsAt: at, aside: true },
|
||||
{ name: "Other Models", used: 100, resetsAt: at, aside: true },
|
||||
{ name: "On-demand", used: 24.69, display: "$123.45 / $500.00", resetsAt: at },
|
||||
{ name: "Total", used: 100, resetsAt: at, aside: true },
|
||||
])
|
||||
const period = seen.find((r) => r.url === PERIOD)
|
||||
expect(seen.find((r) => r.url === HARD)).toEqual({ ...period, url: HARD })
|
||||
})
|
||||
|
||||
test("a team with no limit of the member's but a team hard limit: on-demand without end, every window aside", async () => {
|
||||
for (const period of [
|
||||
{ ...spent, spendLimitUsage: { individualUsed: 900, limitType: "team" } },
|
||||
{ ...spent, spendLimitUsage: { individualUsed: 900, limitType: "team", pooledLimit: "100000" } },
|
||||
]) {
|
||||
const { u } = await onDemand(period, { hardLimit: 2000, perUserMonthlyLimitDollars: 0 })
|
||||
expect(u.windows.every((w) => w.aside)).toBe(true)
|
||||
expect(shape(u)[2]).toEqual({ name: "On-demand", used: 0, display: "$9.00", resetsAt: at, aside: true })
|
||||
}
|
||||
// GetHardLimit unread: the team's pooled limit says it is allowed
|
||||
const { u } = await onDemand({ ...spent, spendLimitUsage: { individualUsed: 900, limitType: "team", pooledLimit: "100000" } }, new Response("no", { status: 500 }))
|
||||
expect(u.windows.every((w) => w.aside)).toBe(true)
|
||||
})
|
||||
|
||||
test("a personal plan's hard limit is its on-demand limit; the top int32 is none", async () => {
|
||||
const { u } = await onDemand({ ...spent, spendLimitUsage: { individualUsed: 500, limitType: "user" } }, { hardLimit: 20 })
|
||||
expect(shape(u).slice(0, 3)).toEqual([
|
||||
{ name: "Cursor Models", used: 100, resetsAt: at, aside: true },
|
||||
{ name: "Other Models", used: 100, resetsAt: at, aside: true },
|
||||
{ name: "On-demand", used: 25, display: "$5.00 / $20.00", resetsAt: at },
|
||||
])
|
||||
const none = (await onDemand({ ...spent, spendLimitUsage: { individualUsed: 500, limitType: "user" } }, { hardLimit: 2147483647 })).u
|
||||
expect(none.windows.every((w) => w.aside)).toBe(true)
|
||||
// spent to its limit: the account is used up again
|
||||
const out = (await onDemand({ ...spent, spendLimitUsage: { individualUsed: 2500, limitType: "user" } }, { hardLimit: 20 })).u
|
||||
expect(shape(out)[2]).toEqual({ name: "On-demand", used: 100, display: "$25.00 / $20.00", resetsAt: at })
|
||||
})
|
||||
|
||||
test("no on-demand allowed, none set or not known: the pools are the allowance, as before", async () => {
|
||||
const before = [
|
||||
{ name: "Cursor Models", used: 100, resetsAt: at },
|
||||
{ name: "Other Models", used: 100, resetsAt: at },
|
||||
{ name: "Total", used: 100, resetsAt: at, aside: true },
|
||||
]
|
||||
const cases = [
|
||||
[{ ...spent, spendLimitUsage: { individualUsed: 0, limitType: "user" } }, {}],
|
||||
[{ ...spent, spendLimitUsage: { individualUsed: 0, limitType: "user" } }, { hardLimit: 50, noUsageBasedAllowed: true }],
|
||||
[{ ...spent, spendLimitUsage: { individualLimit: 0, individualUsed: 0, limitType: "team" } }, { hardLimit: 2000 }],
|
||||
[{ ...spent, spendLimitUsage: { individualUsed: 0, limitType: "team" } }, { hardLimit: 2000, noUsageBasedAllowed: true }],
|
||||
[{ ...spent, spendLimitUsage: { individualUsed: 0, limitType: "team" } }, new Response("no", { status: 403 })],
|
||||
[spent, new Response("no", { status: 500 })],
|
||||
]
|
||||
for (const [i, [period, hard]] of cases.entries()) expect([i, shape((await onDemand(period, hard)).u)]).toEqual([i, before])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user