Mintplex-Labs/anything-llm · error · Error

Your Ollama instance could not be reached or is not respondi

Error message

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.

What it means

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.

Source

Thrown at server/utils/AiProviders/ollama/index.js:236

   * @param {{userPrompt:string, attachments: import("../../helpers").Attachment[]}}
   * @returns {{content: string, images: string[]}}
   */
  #generateContent({ userPrompt, attachments = [] }) {
    if (!attachments.length) return { content: userPrompt };
    const images = attachments.map(
      (attachment) => attachment.contentString.split("base64,").slice(-1)[0]
    );
    return { content: userPrompt, images };
  }

  /**
   * Handles errors from the Ollama API to make them more user friendly.
   * @param {Error} e
   */
  #errorHandler(e) {
    switch (e.message) {
      case "fetch failed":
        throw new Error(
          "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."
        );
      default:
        return e;
    }
  }

  /**
   * Construct the user prompt for this model.
   * @param {{attachments: import("../../helpers").Attachment[]}} param0
   * @returns
   */
  constructPrompt({
    systemPrompt = "",
    contextTexts = [],
    chatHistory = [],
    userPrompt = "",
    attachments = [],

View on GitHub (pinned to 526360e320)

Solutions

  1. Confirm 'ollama serve' is running on the host: curl ${OLLAMA_BASE_PATH}/api/tags returns JSON.
  2. Check the host and port in OLLAMA_BASE_PATH are correct and reachable from the AnythingLLM process.
  3. If remote, verify the reverse proxy / firewall / Docker network permits the connection.
  4. Set OLLAMA_ORIGINS on the Ollama side if CORS/refusal is the cause.

Example fix

# before
OLLAMA_BASE_PATH=http://localhost:11434   # resolves to ::1, refused on some hosts

# after
OLLAMA_BASE_PATH=http://127.0.0.1:11434   # explicit IPv4 loopback
Defensive patterns

Strategy: retry

Validate before calling

const pingOllama = async (basePath) => {
  const res = await fetch(`${basePath.replace(/\/$/, '')}/api/tags`);
  if (!res.ok) throw new Error(`Ollama unreachable: HTTP ${res.status}`);
  return true;
};
await pingOllama(process.env.OLLAMA_BASE_PATH);

Type guard

const isFetchFailed = (e) =>
  !!e && (e.message === 'fetch failed' || e?.cause?.code === 'ECONNREFUSED' || e?.cause?.code === 'ENOTFOUND');

Try / catch

try {
  await llm.streamGetChatCompletion(messages, { temperature });
} catch (e) {
  if (e.message.includes('could not be reached')) {
    // transient connectivity — back off and retry, or surface a health check
    await sleep(backoffMs); return retry();
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: '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.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/45e56fc0244c0ad9. Report an issue: GitHub.