Skip to content

Commit f3df489

Browse files
committed
fix: pass LiteLLM credentials when flushing model cache
When refreshing LiteLLM models, the cache flush was not receiving the required apiKey and baseUrl parameters, causing an 'Invalid URL' error. This fix: - Updates flushModels() to accept optional GetModelsOptions parameter - Passes LiteLLM credentials when flushing cache in both places: 1. When explicitly refreshing via flushRouterModels message 2. When requesting models with new credentials Fixes #9682
1 parent 127ecf6 commit f3df489

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/api/providers/fetchers/modelCache.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,20 @@ export async function initializeModelCacheRefresh(): Promise<void> {
273273
*
274274
* @param router - The router to flush models for.
275275
* @param refresh - If true, immediately fetch fresh data from API
276+
* @param options - Optional provider options (e.g., apiKey, baseUrl) needed for certain providers
276277
*/
277-
export const flushModels = async (router: RouterName, refresh: boolean = false): Promise<void> => {
278+
export const flushModels = async (
279+
router: RouterName,
280+
refresh: boolean = false,
281+
options?: GetModelsOptions,
282+
): Promise<void> => {
278283
if (refresh) {
279284
// Don't delete memory cache - let refreshModels atomically replace it
280285
// This prevents a race condition where getModels() might be called
281286
// before refresh completes, avoiding a gap in cache availability
282-
refreshModels({ provider: router } as GetModelsOptions).catch((error) => {
287+
// Use provided options if available, otherwise fallback to minimal options
288+
const refreshOptions = options || ({ provider: router } as GetModelsOptions)
289+
refreshModels(refreshOptions).catch((error) => {
283290
console.error(`[flushModels] Refresh failed for ${router}:`, error)
284291
})
285292
} else {

src/core/webview/webviewMessageHandler.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,12 @@ export const webviewMessageHandler = async (
876876
// If explicit credentials are provided in message.values (from Refresh Models button),
877877
// flush the cache first to ensure we fetch fresh data with the new credentials
878878
if (message?.values?.litellmApiKey || message?.values?.litellmBaseUrl) {
879-
await flushModels("litellm", true)
879+
const litellmFlushOptions: GetModelsOptions = {
880+
provider: "litellm",
881+
apiKey: litellmApiKey,
882+
baseUrl: litellmBaseUrl,
883+
}
884+
await flushModels("litellm", true, litellmFlushOptions)
880885
}
881886

882887
candidates.push({

0 commit comments

Comments
 (0)