Skip to content

Commit 3702ec7

Browse files
fix(server): custom Codex providers no longer warn about usage
A Codex instance pointed at a custom model_provider (such as a CLIProxyAPI hub) has no account, so Codex rejects account/rateLimits/read with JSON-RPC -32600 and the usage page showed it as a failed check. Only ChatGPT plans have rate limits: skip the read for every other account and report usage as unsupported, the way API-key accounts already were. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8176b58 commit 3702ec7

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎apps/server/src/provider/CodexProvider.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ function codexAccountAuthLabel(account: CodexSchema.V2GetAccountResponse["accoun
122122
return codexPlanLabel(account.planType);
123123
}
124124

125+
/**
126+
* Only ChatGPT plans have rate limits. API keys, Bedrock, and a custom
127+
* `model_provider` (no account, no OpenAI auth required) never report usage.
128+
*/
129+
function codexUsageUnsupported(response: CodexSchema.V2GetAccountResponse): boolean {
130+
return response.account ? response.account.type !== "chatgpt" : !response.requiresOpenaiAuth;
131+
}
132+
125133
export function codexPlanLabel(planType: string | null | undefined): string | undefined {
126134
switch (planType) {
127135
case "free":
@@ -565,7 +573,7 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
565573
),
566574
// Usage is an enrichment: a failure or a slow answer degrades to "no
567575
// usage this probe" rather than costing the account and models.
568-
input.skipNativeUsage
576+
input.skipNativeUsage || codexUsageUnsupported(accountResponse)
569577
? Effect.succeed(undefined)
570578
: withCodexDiscoveryDeadline(
571579
client.request("account/rateLimits/read", null),
@@ -790,7 +798,7 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu
790798
? { status: "ready" as const, auth: managedAuth, message: undefined }
791799
: accountProbeStatus(snapshot);
792800
const usageLimits =
793-
snapshot.account.account?.type === "apiKey"
801+
codexUsageUnsupported(snapshot.account)
794802
? makeUnavailableUsageLimits({ checkedAt, reason: "unsupported" })
795803
: snapshot.rateLimits === undefined || "failure" in snapshot.rateLimits
796804
? makeUnavailableUsageLimits({

‎apps/server/src/provider/ProviderRegistry.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,21 @@ it.layer(
424424
assert.strictEqual(status.auth.status, "unknown");
425425
}),
426426
);
427+
428+
it.effect("reports usage as unsupported for a custom model provider without an account", () =>
429+
Effect.gen(function* () {
430+
const status = yield* checkCodexProviderStatus(defaultCodexSettings, () =>
431+
Effect.succeed(
432+
makeCodexProbeSnapshot({
433+
account: { account: null, requiresOpenaiAuth: false },
434+
}),
435+
),
436+
);
437+
438+
assert.strictEqual(status.usageLimits?.unavailable?.reason, "unsupported");
439+
assert.strictEqual(status.usageLimits?.unavailable?.message, undefined);
440+
}),
441+
);
427442
});
428443

429444
describe("ProviderRegistry.layer", () => {

0 commit comments

Comments
 (0)