@@ -49,6 +49,7 @@ import { makeUnavailableUsageLimits } from "@t3tools/provider-core/server/usageL
4949import {
5050 codexRateLimitsFailureMessage ,
5151 codexRateLimitsToLimits ,
52+ isCodexUsageAuthRequiredError ,
5253 type CodexRateLimitSnapshot ,
5354 type CodexResetCreditsSummary ,
5455} from "./codexUsageLimits.ts" ;
@@ -67,7 +68,7 @@ type CodexRateLimitsProbe =
6768 readonly resetCredits : CodexResetCreditsSummary | null | undefined ;
6869 readonly accountId ?: string | null | undefined ;
6970 }
70- | { readonly failure : string } ;
71+ | { readonly failure : string ; readonly authRequired ?: true } ;
7172
7273const CODEX_APP_SERVER_PROBE_FORCE_KILL_AFTER = "2 seconds" as const ;
7374const CODEX_CATALOG_REFRESH_TIMEOUT_MS = 3_000 ;
@@ -593,7 +594,10 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
593594 ) ,
594595 Effect . catch ( ( error ) =>
595596 Effect . logDebug ( "Codex rate-limit read failed." , { cause : error } ) . pipe (
596- Effect . as < CodexRateLimitsProbe > ( { failure : codexRateLimitsFailureMessage ( error ) } ) ,
597+ Effect . as < CodexRateLimitsProbe > ( {
598+ failure : codexRateLimitsFailureMessage ( error ) ,
599+ ...( isCodexUsageAuthRequiredError ( error ) ? { authRequired : true as const } : { } ) ,
600+ } ) ,
597601 ) ,
598602 ) ,
599603 ) ,
@@ -842,8 +846,17 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu
842846 const accountStatus = managedAuth
843847 ? { status : "ready" as const , auth : managedAuth , message : undefined }
844848 : accountProbeStatus ( snapshot ) ;
849+ // Without an OpenAI account (e.g. a custom model_provider) Codex refuses the
850+ // usage read. The same account shape can still read usage with native auth,
851+ // so only that refusal means unsupported; any other failure stays transient.
852+ const accountlessUsageRefused =
853+ ! snapshot . account . account &&
854+ ! snapshot . account . requiresOpenaiAuth &&
855+ snapshot . rateLimits !== undefined &&
856+ "failure" in snapshot . rateLimits &&
857+ snapshot . rateLimits . authRequired === true ;
845858 const usageLimits =
846- snapshot . account . account ?. type === "apiKey"
859+ snapshot . account . account ?. type === "apiKey" || accountlessUsageRefused
847860 ? makeUnavailableUsageLimits ( { checkedAt, reason : "unsupported" } )
848861 : snapshot . rateLimits === undefined || "failure" in snapshot . rateLimits
849862 ? makeUnavailableUsageLimits ( {
0 commit comments