diff --git a/src/api/providers/fetchers/modelCache.ts b/src/api/providers/fetchers/modelCache.ts index ec9c214cca3..990d0536dd1 100644 --- a/src/api/providers/fetchers/modelCache.ts +++ b/src/api/providers/fetchers/modelCache.ts @@ -273,13 +273,20 @@ export async function initializeModelCacheRefresh(): Promise { * * @param router - The router to flush models for. * @param refresh - If true, immediately fetch fresh data from API + * @param options - Optional provider options (e.g., apiKey, baseUrl) needed for certain providers */ -export const flushModels = async (router: RouterName, refresh: boolean = false): Promise => { +export const flushModels = async ( + router: RouterName, + refresh: boolean = false, + options?: GetModelsOptions, +): Promise => { if (refresh) { // Don't delete memory cache - let refreshModels atomically replace it // This prevents a race condition where getModels() might be called // before refresh completes, avoiding a gap in cache availability - refreshModels({ provider: router } as GetModelsOptions).catch((error) => { + // Use provided options if available, otherwise fallback to minimal options + const refreshOptions = options || ({ provider: router } as GetModelsOptions) + refreshModels(refreshOptions).catch((error) => { console.error(`[flushModels] Refresh failed for ${router}:`, error) }) } else { diff --git a/src/core/webview/webviewMessageHandler.ts b/src/core/webview/webviewMessageHandler.ts index 986dd404708..a36c615db74 100644 --- a/src/core/webview/webviewMessageHandler.ts +++ b/src/core/webview/webviewMessageHandler.ts @@ -876,7 +876,12 @@ export const webviewMessageHandler = async ( // If explicit credentials are provided in message.values (from Refresh Models button), // flush the cache first to ensure we fetch fresh data with the new credentials if (message?.values?.litellmApiKey || message?.values?.litellmBaseUrl) { - await flushModels("litellm", true) + const litellmFlushOptions: GetModelsOptions = { + provider: "litellm", + apiKey: litellmApiKey, + baseUrl: litellmBaseUrl, + } + await flushModels("litellm", true, litellmFlushOptions) } candidates.push({