Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/user/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion packages/provider-cursor/src/server/driver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}),
),
),
);
Expand All @@ -85,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,
Expand Down Expand Up @@ -152,6 +172,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" };
Expand Down
13 changes: 8 additions & 5 deletions packages/provider-cursor/src/server/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 }))),
),
),
),
Expand Down
33 changes: 32 additions & 1 deletion packages/provider-cursor/src/server/usageLimits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,42 @@ 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: "configured-auth" },
{ apiKey: "session-token", usesApiKey: false },
),
).toEqual({
CURSOR_API_KEY: undefined,
CURSOR_AUTH_TOKEN: "configured-auth",
});
expect(
cursorUsageLimitsEnvironment(
{ 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",
});
});

it("uses the advertised percentages and billing-cycle reset", () => {
const limits = cursorUsageResponseToLimits(
{
Expand Down
26 changes: 26 additions & 0 deletions packages/provider-cursor/src/server/usageLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,32 @@ const CursorUsageResponse = Schema.Struct({
),
});

/**
* Limits use a dashboard access token, not an agent API key.
* 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,
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,
...(processEnv.CURSOR_AUTH_TOKEN?.trim()
? {}
: 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,
Expand Down
Loading