Mintplex-Labs/anything-llm · error · Error
Ollama::getChatCompletion failed to communicate with Ollama.
Error message
Ollama::getChatCompletion failed to communicate with Ollama. ${this.#errorHandler(e).message} What it means
Catch-all wrapper around any rejection from this.client.chat(...) in the non-streaming path. It routes the error through #errorHandler, which either rewrites 'fetch failed' into the friendly unreachable message (error 263) or returns the original error; the result is prefixed with 'Ollama::getChatCompletion failed to communicate with Ollama.' This is the umbrella error for all non-network Ollama chat failures.
Source
Thrown at server/utils/AiProviders/ollama/index.js:298
num_ctx: this.promptWindowLimit(),
},
})
.then((res) => {
let content = res.message.content;
if (res.message.thinking)
content = `<think>${res.message.thinking}</think>${content}`;
return {
content,
usage: {
prompt_tokens: res.prompt_eval_count,
completion_tokens: res.eval_count,
total_tokens: res.prompt_eval_count + res.eval_count,
duration: res.eval_duration / 1e9,
},
};
})
.catch((e) => {
throw new Error(
`Ollama::getChatCompletion failed to communicate with Ollama. ${this.#errorHandler(e).message}`
);
})
);
if (!result.output.content || !result.output.content.length)
throw new Error(`Ollama::getChatCompletion text response was empty.`);
return {
textResponse: result.output.content,
metrics: {
prompt_tokens: result.output.usage.prompt_tokens,
completion_tokens: result.output.usage.completion_tokens,
total_tokens: result.output.usage.total_tokens,
outputTps:
result.output.usage.completion_tokens / result.output.usage.duration,
duration: result.output.usage.duration,
model: this.model,View on GitHub (pinned to 526360e320)
Solutions
- Read the suffix after 'failed to communicate with Ollama.' to get the true cause.
- If the suffix is the unreachable message, follow error 263's connectivity steps.
- Run 'ollama list' on the server and confirm this.model is present; 'ollama pull' if missing.
- For context/OOM errors, lower OLLAMA_MODEL_TOKEN_LIMIT or reduce injected context.
Example fix
// before
.catch((e) => {
throw new Error(`Ollama::getChatCompletion failed to communicate with Ollama. ${this.#errorHandler(e).message}`);
})
// after - distinguish network vs model errors for callers
.catch((e) => {
const friendly = this.#errorHandler(e);
const wrapped = new Error(`Ollama::getChatCompletion failed: ${friendly.message}`);
wrapped.code = e?.cause?.code || (e.message === 'fetch failed' ? 'ECONNREFUSED' : 'OLLAMA_ERROR');
throw wrapped;
}) Defensive patterns
Strategy: try-catch
Validate before calling
const ensureOllamaModel = async (client, model) => {
const { models = [] } = await client.list().catch(() => ({ models: [] }));
if (!models.some((m) => m.name === model))
throw new Error(`Ollama model '${model}' is not pulled. Run: ollama pull ${model}`);
};
await ensureOllamaModel(llm.client, llm.model); Type guard
const isOllamaCommError = (e) => !!e && /failed to communicate with Ollama/.test(e.message);
Try / catch
try {
return await llm.getChatCompletion(messages, { temperature });
} catch (e) {
if (e.message.includes('could not be reached')) { /* connectivity path */ }
if (e.message.toLowerCase().includes('model not found')) { /* pull/fix model */ }
throw e;
} Prevention
- Verify the model is pulled with 'ollama list' before pointing chat at it.
- Pre-warm large models (keep_alive) so first-request load failures surface at warmup.
- Cap OLLAMA_MODEL_TOKEN_LIMIT below the model's real context to avoid overflow errors.
When it happens
Trigger: Model not pulled on the Ollama server; model name typo; num_ctx/prompt exceeding the model's capacity; GPU OOM during inference; Ollama internal 500; connection refused (suffix becomes the fetch-failed message); invalid options payload.
Common situations: User selected a model in the UI that was never 'ollama pull'ed; quantized model OOMs on the available VRAM; chat history grew past the context window; Ollama restarted mid-session; wrong model id casing.
Related errors
- Your Ollama instance could not be reached or is not respondi
- Ollama::getChatCompletion text response was empty.
- Stream returned undefined chunk. Aborting reply - check mode
- ${e.message}
- ${e.message}
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/b240b4e2cc51fe25.
Report an issue: GitHub.