janhq/jan · error · Error

Cannot connect to ${provider.provider} at ${provider.base_ur

Error message

Cannot connect to ${provider.provider} at ${provider.base_url}. Please check that the service is running and accessible.

What it means

Thrown when getModels catches an error whose message contains the substring 'fetch' - the signature of a network-level failure from fetchTauri (TypeError: Failed to fetch, DNS failure, connection refused, TLS error, CORS rejection). It reformulates the low-level network error into an actionable message naming the provider and base_url.

Source

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

      const structuredErrorPrefixes = [
        'Authentication failed',
        'Access forbidden',
        'Models endpoint not found',
        'Failed to fetch models from',
      ]

      if (
        error instanceof Error &&
        structuredErrorPrefixes.some((prefix) =>
          (error as Error).message.startsWith(prefix)
        )
      ) {
        throw new Error(error.message)
      }

      // Provide helpful error message for any connection errors
      if (error instanceof Error && error.message.includes('fetch')) {
        throw new Error(
          `Cannot connect to ${provider.provider} at ${provider.base_url}. Please check that the service is running and accessible.`
        )
      }

      // Generic fallback
      throw new Error(
        `Unexpected error while fetching models from ${provider.provider}: ${error instanceof Error ? error.message : 'Unknown error'}`
      )
    }
  }

  async updateSettings(
    providerName: string,
    settings: ProviderSetting[]
  ): Promise<void> {
    try {
      // API keys are persisted to the OS keyring only (via
      // register_provider_config), never to the extension's settings.json.

View on GitHub (pinned to fad3f12a14)

Solutions

  1. Confirm the service is running: curl -i ${base_url}/models from a terminal.
  2. Verify base_url exactly - scheme (http/https), host, port, and no trailing slash / path mismatches.
  3. For localhost providers, confirm the Origin header logic applies; it only triggers for hosts containing 'localhost:' or '127.0.0.1:'.
  4. For self-signed certs, trust the cert or use http locally; check the provider's CORS configuration.

Example fix

// before: localhost provider not started -> 'Cannot connect to llama.cpp at http://127.0.0.1:8080...'
// after: validate reachability when saving provider settings
async function pingProvider(base_url: string, key?: string): Promise<boolean> {
  const headers: Record<string,string> = {}
  if (key) { headers['x-api-key'] = key; headers['Authorization'] = `Bearer ${key}` }
  try { return (await fetch(`${base_url}/models`, { headers })).ok } catch { return false }
}
Defensive patterns

Strategy: retry

Validate before calling

async function canReach(base_url: string): Promise<boolean> {
  try {
    await fetch(`${base_url}/models`, { method: 'GET', mode: 'no-cors' })
    return true
  } catch { return false }
}

Type guard

function isConnectionError(e: unknown): boolean {
  return e instanceof Error && /fetch|network|ECONNREFUSED|ENOTFOUND|certificate|CORS/i.test(e.message)
}

Try / catch

try {
  await provider.getModels(p)
} catch (e) {
  if (isConnectionError(e)) {
    showRetryableError(`Cannot reach ${p.base_url}`, { retry: () => provider.getModels(p) })
  } else throw e
}

Prevention

When it happens

Trigger: fetchTauri rejects with a TypeError such as 'Failed to fetch' - provider host unreachable, wrong base_url scheme/host/port, CORS preflight failure, TLS certificate error, or a localhost service that is not running.

Common situations: User configured a local provider (llama.cpp / Ollama) but it is not running; base_url typo; HTTPS endpoint with a self-signed cert; CORS blocking the request from the Tauri webview; the localhost Origin-header injection (tauri://localhost) did not apply because the host string did not match 'localhost:' or '127.0.0.1:'.

Related errors


AI-assisted analysis of janhq/jan@fad3f12a14 (2026-08-12). Data as JSON: /api/errors/b2e13f6b18aae382. Report an issue: GitHub.