{"record":{"id":"45e56fc0244c0ad9","repo":"Mintplex-Labs/anything-llm","slug":"your-ollama-instance-could-not-be-reached-or-is-no","errorCode":null,"errorMessage":"Your Ollama instance could not be reached or is not responding. Please make sure it is running the API server and your connection information is correct in AnythingLLM.","messagePattern":"Your Ollama instance could not be reached or is not responding\\. Please make sure it is running the API server and your connection information is correct in AnythingLLM\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/ollama/index.js","lineNumber":236,"sourceCode":"   * @param {{userPrompt:string, attachments: import(\"../../helpers\").Attachment[]}}\n   * @returns {{content: string, images: string[]}}\n   */\n  #generateContent({ userPrompt, attachments = [] }) {\n    if (!attachments.length) return { content: userPrompt };\n    const images = attachments.map(\n      (attachment) => attachment.contentString.split(\"base64,\").slice(-1)[0]\n    );\n    return { content: userPrompt, images };\n  }\n\n  /**\n   * Handles errors from the Ollama API to make them more user friendly.\n   * @param {Error} e\n   */\n  #errorHandler(e) {\n    switch (e.message) {\n      case \"fetch failed\":\n        throw new Error(\n          \"Your Ollama instance could not be reached or is not responding. Please make sure it is running the API server and your connection information is correct in AnythingLLM.\"\n        );\n      default:\n        return e;\n    }\n  }\n\n  /**\n   * Construct the user prompt for this model.\n   * @param {{attachments: import(\"../../helpers\").Attachment[]}} param0\n   * @returns\n   */\n  constructPrompt({\n    systemPrompt = \"\",\n    contextTexts = [],\n    chatHistory = [],\n    userPrompt = \"\",\n    attachments = [],","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/ollama/index.js#L218-L254","documentation":"A user-friendly rewrite produced by OllamaAILLM.#errorHandler. When the underlying Ollama/Node error message is exactly 'fetch failed' (Node's global fetch / undici error for any TCP-level failure: connection refused, DNS error, TLS handshake failure, or timeout), the handler throws this actionable message instead. Used by both getChatCompletion and streamGetChatCompletion catch blocks.","triggerScenarios":"Any Ollama client call (chat, list, show) that triggers undici's 'fetch failed' — Ollama server stopped, wrong host/port, DNS resolution failure, TLS mismatch, or a proxy/firewall dropping the connection.","commonSituations":"'ollama serve' not running; OLLAMA_BASE_PATH points at the wrong port (e.g. 11434 vs 8000); remote Ollama behind a reverse proxy that is down; IPv6 vs IPv4 resolution mismatch; CORS/OLLAMA_ORIGINS misconfigured so the connection is refused; Docker network isolation between containers.","solutions":["Confirm 'ollama serve' is running on the host: curl ${OLLAMA_BASE_PATH}/api/tags returns JSON.","Check the host and port in OLLAMA_BASE_PATH are correct and reachable from the AnythingLLM process.","If remote, verify the reverse proxy / firewall / Docker network permits the connection.","Set OLLAMA_ORIGINS on the Ollama side if CORS/refusal is the cause."],"exampleFix":"# before\nOLLAMA_BASE_PATH=http://localhost:11434   # resolves to ::1, refused on some hosts\n\n# after\nOLLAMA_BASE_PATH=http://127.0.0.1:11434   # explicit IPv4 loopback","handlingStrategy":"retry","validationCode":"const pingOllama = async (basePath) => {\n  const res = await fetch(`${basePath.replace(/\\/$/, '')}/api/tags`);\n  if (!res.ok) throw new Error(`Ollama unreachable: HTTP ${res.status}`);\n  return true;\n};\nawait pingOllama(process.env.OLLAMA_BASE_PATH);","typeGuard":"const isFetchFailed = (e) =>\n  !!e && (e.message === 'fetch failed' || e?.cause?.code === 'ECONNREFUSED' || e?.cause?.code === 'ENOTFOUND');","tryCatchPattern":"try {\n  await llm.streamGetChatCompletion(messages, { temperature });\n} catch (e) {\n  if (e.message.includes('could not be reached')) {\n    // transient connectivity — back off and retry, or surface a health check\n    await sleep(backoffMs); return retry();\n  }\n  throw e;\n}","preventionTips":["Use 127.0.0.1 instead of localhost to avoid IPv6 resolution issues.","Run a health check against /api/tags before serving chat requests.","Ensure 'ollama serve' is managed by a process supervisor (systemd/launchd) so it auto-restarts."],"tags":["ollama","network","connectivity","error-handling"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}