affaan-m/ECC · error · AuthenticationError

Ollama connection failed

Error message

Ollama connection failed: {msg}

What it means

The Ollama provider's generate() maps exceptions with '401' or 'connection' in the message to AuthenticationError with the prefix 'Ollama connection failed:'. It fires when the HTTP client cannot reach the local/remote Ollama server, or the server rejects credentials. Note this conflates network unreachability with authentication, since Ollama usually has no auth.

Solutions

  1. Verify Ollama is running: `ollama list` or `curl http://localhost:11434/api/tags`
  2. Check the configured base URL / port for typos and reachability
  3. If behind a proxy, confirm auth headers or disable the auth requirement
  4. Catch AuthenticationError and surface a 'check Ollama server' message to users

Example fix

// before
provider = OllamaProvider(base_url="http://localhost:934")
// after
provider = OllamaProvider(base_url="http://localhost:11434")
Defensive patterns

Strategy: validation

Validate before calling

import urllib.request
try:
    urllib.request.urlopen("http://localhost:11434/api/tags", timeout=2)
    ollama_ready = True
except Exception:
    ollama_ready = False

Try / catch

try:
    resp = provider.generate(inp)
except AuthenticationError as e:
    raise RuntimeError("Cannot reach Ollama — check it is running and the base URL/port") from e

Prevention

When it happens

Trigger: Calling provider.generate() while the Ollama daemon is not running, the host/port in the base URL is wrong, or the server returns 401; any exception message containing 'connection' triggers it.

Common situations: OLLAMA_BASE_URL pointing to the wrong port (11434 is default); Ollama service not started after reboot; Docker container lacking access to host Ollama; reverse proxy requiring auth in front of Ollama.

Understand the failure class

Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/a5cc3c26c28c679d. Report an issue: GitHub.

Appendix: source

Thrown at src/llm/providers/ollama.py:104

                tool_calls = [
                    ToolCall(
                        id=tc.get("id", ""),
                        name=tc.get("function", {}).get("name", ""),
                        arguments=tc.get("function", {}).get("arguments", {}),
                    )
                    for tc in result["message"]["tool_calls"]
                ]

            return LLMOutput(
                content=content,
                tool_calls=tool_calls,
                model=model,
                stop_reason=result.get("done_reason"),
            )
        except Exception as e:
            msg = str(e)
            if "401" in msg or "connection" in msg.lower():
                raise AuthenticationError(f"Ollama connection failed: {msg}", provider=ProviderType.OLLAMA) from e
            if "429" in msg or "rate_limit" in msg.lower():
                raise RateLimitError(msg, provider=ProviderType.OLLAMA) from e
            if "context" in msg.lower() and "length" in msg.lower():
                raise ContextLengthError(msg, provider=ProviderType.OLLAMA) from e
            raise

    def list_models(self) -> list[ModelInfo]:
        return self._models.copy()

    def validate_config(self) -> bool:
        return bool(self.base_url)

    def get_default_model(self) -> str:
        return self.default_model

View on GitHub (pinned to 8321021c54)