fix(providers): retry OpenAI model discovery without auth on failure

When the OpenAI-compatible endpoint rejects the first authenticated
/models request (some upstreams expose the route unauthenticated, or
the configured key only covers chat completions), retry once with no
key and no custom headers before surfacing the original error so the
discovery panel can populate.
This commit is contained in:
LTbinglingfeng
2026-05-25 01:55:45 +08:00
Unverified
parent c23fd6975e
commit dd3c39ec32
@@ -103,7 +103,22 @@ export function useModelDiscovery(
const entryKey = (firstEntry?.apiKey ?? '').trim();
const entryHeaders = parseHeadersText(firstEntry?.headersText ?? '');
const headers = { ...baseHeaders, ...entryHeaders };
next = await modelsApi.fetchModelsViaApiCall(baseUrl, entryKey, headers);
try {
next = await modelsApi.fetchModelsViaApiCall(
baseUrl,
entryKey,
headers
);
} catch (firstErr) {
// Some OpenAI-compatible endpoints expose /models without auth, or
// reject the configured key for the discovery route. Retry once
// without any auth/headers before surfacing the original error.
try {
next = await modelsApi.fetchModelsViaApiCall(baseUrl);
} catch {
throw firstErr;
}
}
}
setModels(next ?? []);
setHasFetched(true);