{"record":{"id":"c4f3da64f6081653","repo":"continuedev/continue","slug":"failed-to-fetch-models-for-provider-error-m","errorCode":null,"errorMessage":"Failed to fetch models for ${provider}: ${error?.message ?? error}","messagePattern":"Failed to fetch models for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/llm/fetchModels.ts","lineNumber":235,"sourceCode":"\nasync function fetchProviderModelsViaListModels(\n  provider: string,\n  apiKey?: string,\n  apiBase?: string,\n): Promise<FetchedModel[]> {\n  try {\n    const cls = LLMClasses.find((llm) => llm.providerName === provider);\n    const defaultApiBase = cls?.defaultOptions?.apiBase;\n\n    const llm = llmFromProviderAndOptions(provider, {\n      apiKey,\n      apiBase: apiBase || defaultApiBase,\n      model: \"\",\n    });\n    const modelIds = await llm.listModels();\n    return modelIds.map((id) => ({ name: id }));\n  } catch (error: any) {\n    throw new Error(\n      `Failed to fetch models for ${provider}: ${error?.message ?? error}`,\n    );\n  }\n}\n\nexport async function fetchModels(\n  provider: string,\n  apiKey?: string,\n  apiBase?: string,\n): Promise<FetchedModel[]> {\n  switch (provider) {\n    case \"ollama\":\n      return fetchOllamaModels();\n    case \"openrouter\":\n      return fetchOpenRouterModels();\n    case \"anthropic\":\n      return fetchAnthropicModels(apiKey);\n    case \"gemini\":","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/continuedev/continue/blob/5522c6f44ca0ac3528b37244818fbfa39b5af470/core/llm/fetchModels.ts#L217-L253","documentation":"A generic wrapper thrown by fetchProviderModelsViaListModels when constructing an LLM client for a provider and calling llm.listModels() fails for any reason; the original error message is embedded with the provider name. It aggregates auth, URL, and connectivity failures for arbitrary providers.","triggerScenarios":"Any provider whose listModels call fails: wrong apiBase, unreachable server, invalid API key, or a provider constructor throwing on model: \"\".","commonSituations":"Misconfigured apiBase for LM Studio/vLLM/Ollama-style local servers; server not running; custom provider with a bad fetch implementation; auth failures for hosted providers.","solutions":["Read the embedded inner message — it identifies the real cause (connection refused vs 401 vs invalid URL)","Verify the provider's apiBase is correct and the server is running (curl the base URL)","Check the provider's API key/credentials","Retry transient network failures with backoff"],"exampleFix":"// before\n{ provider: \"openai\", apiBase: \"http://localhost:1234\" } // server down\n# start the server, then:\n// after\n{ provider: \"openai\", apiBase: \"http://localhost:1234\" } // curl http://localhost:1234/v1/models now returns JSON","handlingStrategy":"fallback","validationCode":"const health = await fetch(apiBase.replaceAll(/\\/$/, '') + '/models'); if (!health.ok) disableProviderModelListing();","typeGuard":null,"tryCatchPattern":"catch (e) { if (e.message.startsWith('Failed to fetch models for')) { inspectInnerMessageAndFix(e.message); } else throw e; }","preventionTips":["Health-check provider apiBase before listing models","Keep local model lists as fallback","Include the inner error cause in your logging"],"tags":["model-list","provider","network","configuration"],"backgroundTag":"provider-model-list-failed","analyzedSha":"5522c6f44ca0ac3528b37244818fbfa39b5af470","analyzedAt":"2026-08-27T11:28:54.683Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}