jlcodes99/cockpit-tools · warning
[CodexModelProviders] 额度类型探测失败
Error message
[CodexModelProviders] 额度类型探测失败
What it means
In the Codex model provider manager controller, after saving a provider the app probes its usage/quota endpoint to detect the integration type (usageSummary.mode) and persists it via saveCodexModelProviderDetectedIntegrationType. If the probe throws, the warning is logged and the provider is still saved — only the detected quota type is not recorded, so the UI may show 'unknown' quota mode.
Source
Thrown at src/components/codex/CodexModelProviderManager.tsx:2271
apiKey: newApiKey,
integrationType: savedProvider.integrationType ?? null,
});
setProviderUsageMap((previous) => ({
...previous,
[savedProvider.id]: { loading: false, summary: usageSummary },
}));
if (
(usageSummary.mode === "sub2api" ||
usageSummary.mode === "new_api") &&
usageSummary.mode !== savedProvider.integrationType
) {
await saveCodexModelProviderDetectedIntegrationType(
savedProvider.id,
usageSummary.mode,
);
}
} catch (usageErr) {
console.warn("[CodexModelProviders] 额度类型探测失败", usageErr);
}
}
if (savedProvider && currentEditingProvider) {
const linkedAccountIds = findCodexAccountsReferencingModelProvider(
currentEditingProvider,
accounts,
);
if (linkedAccountIds.length > 0) {
const presetId = resolveCodexApiProviderPresetId(savedProvider.baseUrl);
const isOpenAIOfficial = presetId === "openai_official";
const wireApi = resolveProviderWireApi(savedProvider);
const updatedAccountCount = await syncCodexApiKeyProviderAccounts({
accountIds: linkedAccountIds,
apiBaseUrl: savedProvider.baseUrl,
apiProviderMode: isOpenAIOfficial ? "openai_builtin" : "custom",
apiProviderId:
presetId === CODEX_API_PROVIDER_CUSTOM_ID
? savedProvider.idView on GitHub (pinned to 1ed8b77992)
Solutions
- Read the logged usageErr for the concrete cause (401 → fix API key; timeout/ECONNREFUSED → fix URL/network).
- Verify the provider's base URL and API key in the provider edit form and test connectivity.
- If the endpoint intentionally has no usage API, ignore the warning and set the quota type manually in provider settings.
- Re-save the provider once the endpoint is reachable so detection reruns.
Example fix
// before
} catch (usageErr) {
console.warn("[CodexModelProviders] 额度类型探测失败", usageErr);
}
// after
} catch (usageErr) {
console.warn("[CodexModelProviders] 额度类型探测失败", usageErr);
await saveCodexModelProviderDetectedIntegrationType(savedProvider.id, 'unknown');
} Defensive patterns
Strategy: try-catch
Validate before calling
// probe only when endpoint config looks complete
if (!savedProvider.baseUrl || !savedProvider.apiKey) {
await saveCodexModelProviderDetectedIntegrationType(savedProvider.id, 'unknown');
return;
}
Type guard
function isProbeableProvider(p: CodexModelProvider | undefined): p is CodexModelProvider & { baseUrl: string; apiKey: string } {
return !!p && typeof p.baseUrl === 'string' && p.baseUrl.startsWith('http') && typeof p.apiKey === 'string' && p.apiKey.length > 0;
}
Try / catch
try {
const usageSummary = await probeUsageEndpoint(savedProvider);
await saveCodexModelProviderDetectedIntegrationType(savedProvider.id, usageSummary.mode);
} catch (usageErr) {
console.warn("[CodexModelProviders] 额度类型探测失败", usageErr);
// provider already saved; set fallback mode so UI isn't stuck on 'detecting'
}
Prevention
- Validate base URL and API key before saving a provider
- Add a request timeout to the usage probe so slow relays fail fast
- Treat probe failure as non-fatal — the provider save must succeed regardless
- Provide a manual quota-type selector as a fallback when detection fails
When it happens
Trigger: Probing the provider's usage endpoint fails: unreachable custom base URL, invalid/expired API key, endpoint not implementing the expected usage API, TLS errors on self-signed certs, or a timeout on slow relays.
Common situations: Self-hosted/proxied Codex-compatible endpoints that don't expose the usage API, wrong API key pasted into the provider config, network blocking the endpoint, or a relay returning HTML instead of JSON.
Related errors
- 刷新 Codex 账号资料失败:
- OAuth 回调服务器错误: {}
- 刷新配额失败: {}
- OAuth 回调服务器错误: {}
- messages.rawLineNoRefreshToken(item.lineNumber)
AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05).
Data as JSON: /api/errors/5ce43b82e5d13fc1.
Report an issue: GitHub.