From 2c267e91084f814144088a805522be6a0a9906ea Mon Sep 17 00:00:00 2001 From: wSedlacek Date: Sat, 31 Oct 2026 04:51:38 -0700 Subject: [PATCH 1/2] 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 | 9 ++++--- .../provider-cursor/src/server/driver.test.ts | 17 +++++++++++- packages/provider-cursor/src/server/driver.ts | 7 +++-- .../src/server/usageLimits.test.ts | 27 ++++++++++++++++++- .../provider-cursor/src/server/usageLimits.ts | 21 +++++++++++++++ 5 files changed, 73 insertions(+), 8 deletions(-) diff --git a/docs/user/usage.md b/docs/user/usage.md index 447924a072eff..4679a5fe48b34 100644 --- a/docs/user/usage.md +++ b/docs/user/usage.md @@ -133,10 +133,11 @@ belong to the remote server. Limits need an OpenCode Go API key, or an OpenCode in OpenCode with an API key. A Console browser sign-in alone does not report them. You can also add 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, using the CLI login or -`CURSOR_AUTH_TOKEN`. On macOS, this includes the default Keychain login after you enable Cursor -usage. Keychain login is used for limits only with Cursor's default API endpoint. If you configure -a custom Cursor endpoint, use an explicit token or file-based CLI login for limits. +its monthly allowance, including separate Auto and API usage, using the T3 browser sign-in, the CLI +login, or `CURSOR_AUTH_TOKEN`. On macOS, this includes the default Keychain login after you enable +Cursor usage. Keychain login is used for limits only with Cursor's default API endpoint. If you +configure a custom Cursor endpoint, use an explicit token or file-based CLI login for limits. +An explicit `CURSOR_API_KEY` does not report subscription 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 5a3202fd20e4d..c5e31178ec02e 100644 --- a/packages/provider-cursor/src/server/driver.test.ts +++ b/packages/provider-cursor/src/server/driver.test.ts @@ -21,6 +21,7 @@ import * as Option from "effect/Option"; import * as Stream from "effect/Stream"; import { vi } from "vite-plus/test"; import * as HttpClient from "effect/http/HttpClient"; +import * as HttpClientResponse from "effect/http/HttpClientResponse"; import { DEFAULT_HANDOFF_TOKEN_CAP, @@ -61,7 +62,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"); + }), ), ), ); @@ -141,6 +153,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 de7251fb56b10..1ea54b61074d4 100644 --- a/packages/provider-cursor/src/server/driver.ts +++ b/packages/provider-cursor/src/server/driver.ts @@ -10,7 +10,7 @@ import * as FileSystem from "effect/FileSystem"; import * as Path from "effect/Path"; import * as Schema from "effect/Schema"; import * as HttpClient from "effect/http/HttpClient"; -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"; @@ -236,7 +236,10 @@ export const CursorDriver: ProviderDriver< Effect.flatMap((settings) => readCursorUsageLimits( effectiveConfig, - { ...processEnv, CURSOR_API_KEY: apiKey }, + cursorUsageLimitsEnvironment(processEnv, { + apiKey, + usesApiKey: auth.usesApiKey, + }), settings.cursorKeychainUsageEnabled, ), ), diff --git a/packages/provider-cursor/src/server/usageLimits.test.ts b/packages/provider-cursor/src/server/usageLimits.test.ts index 1b4cadf88ae3f..978453d09903e 100644 --- a/packages/provider-cursor/src/server/usageLimits.test.ts +++ b/packages/provider-cursor/src/server/usageLimits.test.ts @@ -7,7 +7,11 @@ import * as Path from "effect/Path"; import * as HttpClient from "effect/http/HttpClient"; import * as HttpClientResponse from "effect/http/HttpClientResponse"; import * as CursorKeychain from "./CursorKeychain.ts"; -import { cursorUsageResponseToLimits, readCursorUsageLimits } from "./usageLimits.ts"; +import { + cursorUsageLimitsEnvironment, + cursorUsageResponseToLimits, + readCursorUsageLimits, +} from "./usageLimits.ts"; const withNodeServices = ( effect: Effect.Effect, @@ -23,6 +27,27 @@ const withNodeServices = ( 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 049e646d2c492..c29722f18a5c6 100644 --- a/packages/provider-cursor/src/server/usageLimits.ts +++ b/packages/provider-cursor/src/server/usageLimits.ts @@ -32,6 +32,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 cc799c928ca2eb60b15e4e43684eff4062f0dbc5 Mon Sep 17 00:00:00 2001 From: wSedlacek Date: Sat, 31 Oct 2026 07:31:10 -0700 Subject: [PATCH 2/2] 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 978453d09903e..dc9de9ac80954 100644 --- a/packages/provider-cursor/src/server/usageLimits.test.ts +++ b/packages/provider-cursor/src/server/usageLimits.test.ts @@ -30,18 +30,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 c29722f18a5c6..d6b6963ed72b1 100644 --- a/packages/provider-cursor/src/server/usageLimits.ts +++ b/packages/provider-cursor/src/server/usageLimits.ts @@ -34,7 +34,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, @@ -49,7 +50,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 } + : {}), }; }