janhq/jan · error

Failed to fetch models from

Error message

Failed to fetch models from ${provider.provider}: ${response.status} ${response.statusText}

What it means

Generic throw for any non-OK response from the provider's /models endpoint that isn't 401, 403, or 404. It reports the raw status code and status text so the developer can diagnose provider-specific failures like 429 rate limiting, 5xx server errors, or 400 bad requests.

Solutions

  1. Read the status code in the message: for 429 wait/back off and retry later or check quota.
  2. For 5xx check the provider's status page or restart the local server.
  3. For 400, verify the base URL and headers match the expected API (e.g. Anthropic needs anthropic-version).
  4. Retry the fetch; if persistent, test the endpoint directly with curl to see the response body.

Example fix

// before: hammering a rate-limited endpoint in a loop
await fetchModelsFromProvider(provider)
// after: back off on 429
if (err.message.includes('429')) await new Promise(r => setTimeout(r, 5000))
Defensive patterns

Strategy: retry

Try / catch

try {
  await fetchModelsFromProvider(provider)
} catch (e) {
  const m = e instanceof Error ? e.message : ''
  if (m.includes('429')) await backoffAndRetry()      // rate limited
  else if (/5\d\d/.test(m)) scheduleRetryLater()       // server error
  else reportToUser(m)
}

Prevention

When it happens

Trigger: GET `${provider.base_url}/models` returned a status other than 401/403/404 (e.g. 429, 500, 502, 400) and no alternative key attempt succeeded.

Common situations: Provider rate-limits the account (429); upstream outage or gateway error (5xx); malformed request rejected by an unusual server (400); quota exhausted on a hosted provider.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of janhq/jan@7205d770c1 (2026-09-17). Data as JSON: /api/errors/885d69eb19c1dbfe. Report an issue: GitHub.

Appendix: source

Thrown at web-app/src/services/providers/tauri.ts:217

        }

        if (!response.ok) {
          if (response.status === 401) {
            throw new Error(
              `Authentication failed: API key is required or invalid for ${provider.provider}`
            )
          }
          if (response.status === 403) {
            throw new Error(
              `Access forbidden: Check your API key permissions for ${provider.provider}`
            )
          }
          if (response.status === 404) {
            throw new Error(
              `Models endpoint not found for ${provider.provider}. Check the base URL configuration.`
            )
          }
          throw new Error(
            `Failed to fetch models from ${provider.provider}: ${response.status} ${response.statusText}`
          )
        }

        const data = await response.json()

        if (data.data && Array.isArray(data.data)) {
          return data.data
            .map((model: { id: string }) => model.id)
            .filter(Boolean)
        }
        if (Array.isArray(data)) {
          return data
            .filter(Boolean)
            .map((model) =>
              typeof model === 'object' && 'id' in model ? model.id : model
            )
        }

View on GitHub (pinned to 7205d770c1)