Skip to content

Commit 76b4cd4

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 05696c6 commit 76b4cd4

2 files changed

Lines changed: 38 additions & 16 deletions

File tree

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

Lines changed: 23 additions & 16 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),
@@ -789,21 +797,20 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu
789797
const accountStatus = managedAuth
790798
? { status: "ready" as const, auth: managedAuth, message: undefined }
791799
: accountProbeStatus(snapshot);
792-
const usageLimits =
793-
snapshot.account.account?.type === "apiKey"
794-
? makeUnavailableUsageLimits({ checkedAt, reason: "unsupported" })
795-
: snapshot.rateLimits === undefined || "failure" in snapshot.rateLimits
796-
? makeUnavailableUsageLimits({
797-
checkedAt,
798-
reason: "probeFailed",
799-
...(snapshot.rateLimits ? { message: snapshot.rateLimits.failure } : {}),
800-
})
801-
: codexRateLimitsToLimits({
802-
snapshot: snapshot.rateLimits.snapshot,
803-
rateLimitsByLimitId: snapshot.rateLimits.rateLimitsByLimitId,
804-
resetCredits: snapshot.rateLimits.resetCredits,
805-
checkedAt,
806-
});
800+
const usageLimits = codexUsageUnsupported(snapshot.account)
801+
? makeUnavailableUsageLimits({ checkedAt, reason: "unsupported" })
802+
: snapshot.rateLimits === undefined || "failure" in snapshot.rateLimits
803+
? makeUnavailableUsageLimits({
804+
checkedAt,
805+
reason: "probeFailed",
806+
...(snapshot.rateLimits ? { message: snapshot.rateLimits.failure } : {}),
807+
})
808+
: codexRateLimitsToLimits({
809+
snapshot: snapshot.rateLimits.snapshot,
810+
rateLimitsByLimitId: snapshot.rateLimits.rateLimitsByLimitId,
811+
resetCredits: snapshot.rateLimits.resetCredits,
812+
checkedAt,
813+
});
807814

808815
return buildServerProvider({
809816
presentation: CODEX_PRESENTATION,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,21 @@ it.layer(
416416
assert.strictEqual(status.auth.status, "unknown");
417417
}),
418418
);
419+
420+
it.effect("reports usage as unsupported for a custom model provider without an account", () =>
421+
Effect.gen(function* () {
422+
const status = yield* checkCodexProviderStatus(defaultCodexSettings, () =>
423+
Effect.succeed(
424+
makeCodexProbeSnapshot({
425+
account: { account: null, requiresOpenaiAuth: false },
426+
}),
427+
),
428+
);
429+
430+
assert.strictEqual(status.usageLimits?.unavailable?.reason, "unsupported");
431+
assert.strictEqual(status.usageLimits?.unavailable?.message, undefined);
432+
}),
433+
);
419434
});
420435

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

0 commit comments

Comments
 (0)