From 3a8eca1b0157d6284a3190956668fa6e5036ea73 Mon Sep 17 00:00:00 2001 From: wSedlacek Date: Sat, 31 Oct 2026 04:51:38 -0700 Subject: [PATCH 1/3] fix(provider-cursor): report usage limits after browser sign-in Browser sessions were passed as CURSOR_API_KEY into the limits probe, which marks API keys unsupported, so Limits stayed empty while token history still worked. Map browser credentials to CURSOR_AUTH_TOKEN instead. Co-authored-by: Cursor --- docs/user/usage.md | 6 ++--- .../provider-cursor/src/server/driver.test.ts | 16 ++++++++++- packages/provider-cursor/src/server/driver.ts | 13 +++++---- .../src/server/usageLimits.test.ts | 27 ++++++++++++++++++- .../provider-cursor/src/server/usageLimits.ts | 21 +++++++++++++++ 5 files changed, 73 insertions(+), 10 deletions(-) diff --git a/docs/user/usage.md b/docs/user/usage.md index e6b3a46d5a14e..1fb47c342accf 100644 --- a/docs/user/usage.md +++ b/docs/user/usage.md @@ -157,9 +157,9 @@ in OpenCode with an API key. A Console browser sign-in alone does not report the your Go API key as `OPENCODE_API_KEY` in the OpenCode instance's **Environment variables**, then 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. +otherwise for the account you signed in with in T3 (as a dashboard auth token) 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. 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/driver.test.ts b/packages/provider-cursor/src/server/driver.test.ts index 213d413b6dee2..20cf2fd933ad0 100644 --- a/packages/provider-cursor/src/server/driver.test.ts +++ b/packages/provider-cursor/src/server/driver.test.ts @@ -60,7 +60,18 @@ const layerTest = TestProviderHost.layer({ runBackgroundWork: false }).pipe( Layer.provideMerge( Layer.succeed( HttpClient.HttpClient, - HttpClient.make(() => Effect.die("Disabled Cursor must not make an HTTP request")), + HttpClient.make((request) => { + if (request.url.includes("GetCurrentPeriodUsage")) { + expect(request.headers.authorization).toBe("Bearer instance-browser-key"); + return Effect.succeed( + HttpClientResponse.fromWeb( + request, + Response.json({ planUsage: { totalPercentUsed: 42 } }), + ), + ); + } + return Effect.die("Disabled Cursor must not make an HTTP request"); + }), ), ), ); @@ -152,6 +163,9 @@ it.layer(layerTest)("CursorDriver", (it) => { email: "cursor@example.com", }, setup: { canAuthenticate: true, canInstall: false }, + usageLimits: { + windows: [{ id: "totalPercentUsed", usedPercent: 42 }], + }, }); const threadId = ThreadId.make("cursor-browser-thread"); const modelSelection = { instanceId: input.instanceId, model: "auto" }; diff --git a/packages/provider-cursor/src/server/driver.ts b/packages/provider-cursor/src/server/driver.ts index 4b7477295fbd8..67aa6f2158c1f 100644 --- a/packages/provider-cursor/src/server/driver.ts +++ b/packages/provider-cursor/src/server/driver.ts @@ -11,7 +11,7 @@ import * as Path from "effect/Path"; import * as Schema from "effect/Schema"; import * as HttpClient from "effect/http/HttpClient"; import { cursorRateModel } from "./accountUsage.ts"; -import { readCursorUsageLimits } from "./usageLimits.ts"; +import { cursorUsageLimitsEnvironment, readCursorUsageLimits } from "./usageLimits.ts"; import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost"; import { makeCursorTextGeneration } from "./textGeneration.ts"; @@ -232,10 +232,13 @@ export const CursorDriver: ProviderDriver< snapshot.auth.status === "authenticated" ), (snapshot) => - readCursorUsageLimits(effectiveConfig, { - ...processEnv, - CURSOR_API_KEY: apiKey, - }).pipe(Effect.map((usageLimits) => ({ ...snapshot, usageLimits }))), + readCursorUsageLimits( + effectiveConfig, + cursorUsageLimitsEnvironment(processEnv, { + apiKey, + usesApiKey: auth.usesApiKey, + }), + ).pipe(Effect.map((usageLimits) => ({ ...snapshot, usageLimits }))), ), ), ), diff --git a/packages/provider-cursor/src/server/usageLimits.test.ts b/packages/provider-cursor/src/server/usageLimits.test.ts index e969106812e6e..6379f3664d6b6 100644 --- a/packages/provider-cursor/src/server/usageLimits.test.ts +++ b/packages/provider-cursor/src/server/usageLimits.test.ts @@ -2,11 +2,36 @@ import { describe, expect, it } from "@effect/vitest"; import * as Effect from "effect/Effect"; import * as HttpClient from "effect/http/HttpClient"; import * as HttpClientResponse from "effect/http/HttpClientResponse"; -import { cursorUsageResponseToLimits, readCursorUsageLimits } from "./usageLimits.ts"; +import { + cursorUsageLimitsEnvironment, + cursorUsageResponseToLimits, + readCursorUsageLimits, +} from "./usageLimits.ts"; describe("Cursor usage limits", () => { const checkedAt = "2026-09-16T00:00:00.000Z"; + it("maps browser sessions to CURSOR_AUTH_TOKEN and keeps explicit API keys as CURSOR_API_KEY", () => { + expect( + cursorUsageLimitsEnvironment( + { CURSOR_API_KEY: "stale-env-key", CURSOR_AUTH_TOKEN: "stale-auth" }, + { apiKey: "session-token", usesApiKey: false }, + ), + ).toEqual({ + CURSOR_API_KEY: undefined, + CURSOR_AUTH_TOKEN: "session-token", + }); + expect( + cursorUsageLimitsEnvironment( + { HOME: "/tmp" }, + { apiKey: "user-api-key", usesApiKey: true }, + ), + ).toEqual({ + HOME: "/tmp", + CURSOR_API_KEY: "user-api-key", + }); + }); + it("uses the advertised percentages and billing-cycle reset", () => { const limits = cursorUsageResponseToLimits( { diff --git a/packages/provider-cursor/src/server/usageLimits.ts b/packages/provider-cursor/src/server/usageLimits.ts index 48ab708554206..4ed84daeab240 100644 --- a/packages/provider-cursor/src/server/usageLimits.ts +++ b/packages/provider-cursor/src/server/usageLimits.ts @@ -27,6 +27,27 @@ const CursorUsageResponse = Schema.Struct({ ), }); +/** + * Limits use a dashboard access token, not an agent API key. + * Browser sign-in reuses the session as CURSOR_AUTH_TOKEN; an explicit API key stays unsupported. + */ +export function cursorUsageLimitsEnvironment( + processEnv: NodeJS.ProcessEnv, + options: { + readonly apiKey: string | undefined; + readonly usesApiKey: boolean; + }, +): NodeJS.ProcessEnv { + if (options.usesApiKey) { + return { ...processEnv, CURSOR_API_KEY: options.apiKey }; + } + return { + ...processEnv, + CURSOR_API_KEY: undefined, + ...(options.apiKey ? { CURSOR_AUTH_TOKEN: options.apiKey } : {}), + }; +} + /** Cursor's dashboard percentages include bonus usage; spend / limit does not. */ export function cursorUsageResponseToLimits( response: typeof CursorUsageResponse.Type, From 20fa697056f7fbe7cf76769f67a4c9e86ec8b218 Mon Sep 17 00:00:00 2001 From: wSedlacek Date: Sat, 31 Oct 2026 07:31:10 -0700 Subject: [PATCH 2/3] fix(provider-cursor): keep configured CURSOR_AUTH_TOKEN for limits Browser sign-in should only supply a session token when no dashboard auth token is already set. Co-authored-by: Cursor --- .../provider-cursor/src/server/usageLimits.test.ts | 14 ++++++++++---- packages/provider-cursor/src/server/usageLimits.ts | 9 +++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/provider-cursor/src/server/usageLimits.test.ts b/packages/provider-cursor/src/server/usageLimits.test.ts index 6379f3664d6b6..248478f268a3d 100644 --- a/packages/provider-cursor/src/server/usageLimits.test.ts +++ b/packages/provider-cursor/src/server/usageLimits.test.ts @@ -14,18 +14,24 @@ describe("Cursor usage limits", () => { it("maps browser sessions to CURSOR_AUTH_TOKEN and keeps explicit API keys as CURSOR_API_KEY", () => { expect( cursorUsageLimitsEnvironment( - { CURSOR_API_KEY: "stale-env-key", CURSOR_AUTH_TOKEN: "stale-auth" }, + { CURSOR_API_KEY: "stale-env-key", CURSOR_AUTH_TOKEN: "configured-auth" }, { apiKey: "session-token", usesApiKey: false }, ), ).toEqual({ CURSOR_API_KEY: undefined, - CURSOR_AUTH_TOKEN: "session-token", + CURSOR_AUTH_TOKEN: "configured-auth", }); expect( cursorUsageLimitsEnvironment( - { HOME: "/tmp" }, - { apiKey: "user-api-key", usesApiKey: true }, + { CURSOR_API_KEY: "stale-env-key" }, + { apiKey: "session-token", usesApiKey: false }, ), + ).toEqual({ + CURSOR_API_KEY: undefined, + CURSOR_AUTH_TOKEN: "session-token", + }); + expect( + cursorUsageLimitsEnvironment({ HOME: "/tmp" }, { apiKey: "user-api-key", usesApiKey: true }), ).toEqual({ HOME: "/tmp", CURSOR_API_KEY: "user-api-key", diff --git a/packages/provider-cursor/src/server/usageLimits.ts b/packages/provider-cursor/src/server/usageLimits.ts index 4ed84daeab240..aa75229299d1c 100644 --- a/packages/provider-cursor/src/server/usageLimits.ts +++ b/packages/provider-cursor/src/server/usageLimits.ts @@ -29,7 +29,8 @@ const CursorUsageResponse = Schema.Struct({ /** * Limits use a dashboard access token, not an agent API key. - * Browser sign-in reuses the session as CURSOR_AUTH_TOKEN; an explicit API key stays unsupported. + * Keep a configured CURSOR_AUTH_TOKEN; otherwise browser sign-in supplies the session. + * An explicit API key stays unsupported. */ export function cursorUsageLimitsEnvironment( processEnv: NodeJS.ProcessEnv, @@ -44,7 +45,11 @@ export function cursorUsageLimitsEnvironment( return { ...processEnv, CURSOR_API_KEY: undefined, - ...(options.apiKey ? { CURSOR_AUTH_TOKEN: options.apiKey } : {}), + ...(processEnv.CURSOR_AUTH_TOKEN?.trim() + ? {} + : options.apiKey + ? { CURSOR_AUTH_TOKEN: options.apiKey } + : {}), }; } From d2e1050c38ee8c5cfa98af632c3d096bef1bd90f Mon Sep 17 00:00:00 2001 From: wSedlacek Date: Mon, 16 Nov 2026 04:50:00 -0800 Subject: [PATCH 3/3] test(provider-cursor): mock usage limits on the browser auth client Co-authored-by: Cursor --- packages/provider-cursor/src/server/driver.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/provider-cursor/src/server/driver.test.ts b/packages/provider-cursor/src/server/driver.test.ts index 20cf2fd933ad0..00a5ee05865fd 100644 --- a/packages/provider-cursor/src/server/driver.test.ts +++ b/packages/provider-cursor/src/server/driver.test.ts @@ -96,6 +96,15 @@ it.layer(layerTest)("CursorDriver", (it) => { const requests: Array<{ url: string; authorization: string | undefined }> = []; const client = HttpClient.make((request) => { requests.push({ url: request.url, authorization: request.headers.authorization }); + if (request.url.includes("GetCurrentPeriodUsage")) { + expect(request.headers.authorization).toBe("Bearer instance-browser-key"); + return Effect.succeed( + HttpClientResponse.fromWeb( + request, + Response.json({ planUsage: { totalPercentUsed: 42 } }), + ), + ); + } return Effect.succeed( HttpClientResponse.fromWeb( request,