continuedev/continue · warning
Failed to fetch models for ${provider}: ${error?.message ??
Error message
Failed to fetch models for ${provider}: ${error?.message ?? error} What it means
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.
Source
Thrown at core/llm/fetchModels.ts:235
async function fetchProviderModelsViaListModels(
provider: string,
apiKey?: string,
apiBase?: string,
): Promise<FetchedModel[]> {
try {
const cls = LLMClasses.find((llm) => llm.providerName === provider);
const defaultApiBase = cls?.defaultOptions?.apiBase;
const llm = llmFromProviderAndOptions(provider, {
apiKey,
apiBase: apiBase || defaultApiBase,
model: "",
});
const modelIds = await llm.listModels();
return modelIds.map((id) => ({ name: id }));
} catch (error: any) {
throw new Error(
`Failed to fetch models for ${provider}: ${error?.message ?? error}`,
);
}
}
export async function fetchModels(
provider: string,
apiKey?: string,
apiBase?: string,
): Promise<FetchedModel[]> {
switch (provider) {
case "ollama":
return fetchOllamaModels();
case "openrouter":
return fetchOpenRouterModels();
case "anthropic":
return fetchAnthropicModels(apiKey);
case "gemini":View on GitHub (pinned to 5522c6f44c)
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
Example fix
// before
{ provider: "openai", apiBase: "http://localhost:1234" } // server down
# start the server, then:
// after
{ provider: "openai", apiBase: "http://localhost:1234" } // curl http://localhost:1234/v1/models now returns JSON Defensive patterns
Strategy: fallback
Validate before calling
const health = await fetch(apiBase.replaceAll(/\/$/, '') + '/models'); if (!health.ok) disableProviderModelListing();
Try / catch
catch (e) { if (e.message.startsWith('Failed to fetch models for')) { inspectInnerMessageAndFix(e.message); } else throw e; } Prevention
- Health-check provider apiBase before listing models
- Keep local model lists as fallback
- Include the inner error cause in your logging
When it happens
Trigger: Any provider whose listModels call fails: wrong apiBase, unreachable server, invalid API key, or a provider constructor throwing on model: "".
Common situations: 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.
Related errors
- Failed to fetch Ollama library: ${response.status}
- Failed to fetch OpenRouter models: ${response.status}
- Failed to fetch Anthropic models: ${response.status}
- Failed to fetch Gemini models: ${response.status}
- Not enough context available to include the system message,
AI-assisted analysis of continuedev/continue@5522c6f44c (2026-08-27).
Data as JSON: /api/errors/c4f3da64f6081653.
Report an issue: GitHub.