Fosowl/agenticSeek · error · Exception

Ollama connection failed at {host}. Check if the server is

Error message

Ollama connection failed at {host}. Check if the server is running.

What it means

In Provider.ollama_fn (sources/llm_provider.py:189), an httpx.ConnectError from the Ollama client chat() call is re-raised as 'Ollama connection failed at <host>. Check if the server is running.'. It means the TCP connection to the Ollama daemon could not be established at the computed host URL.

Source

Thrown at sources/llm_provider.py:189

        if self.is_local:
            server_port = self.server_address.split(":")[-1] if ":" in str(self.server_address) else "11434"
            host = f"{self.internal_url}:{server_port}"
        else:
            host = f"http://{self.server_address}"
        client = OllamaClient(host=host)

        try:
            stream = client.chat(
                model=self.model,
                messages=history,
                stream=True,
            )
            for chunk in stream:
                if verbose:
                    print(chunk["message"]["content"], end="", flush=True)
                thought += chunk["message"]["content"]
        except httpx.ConnectError as e:
            raise Exception(
                f"\nOllama connection failed at {host}. Check if the server is running."
            ) from e
        except Exception as e:
            if hasattr(e, 'status_code') and e.status_code == 404:
                animate_thinking(f"Downloading {self.model}...")
                client.pull(self.model)
                return self.ollama_fn(history, verbose)
            if "refused" in str(e).lower():
                raise Exception(
                    f"Ollama connection refused at {host}. Is the server running?"
                ) from e
            raise e

        return thought

    def huggingface_fn(self, history, verbose=False):
        """
        Use huggingface to generate text.

View on GitHub (pinned to ae57a23577)

Solutions

  1. Start the Ollama server: run 'ollama serve' (or start the desktop app) and verify with curl http://localhost:11434/api/tags.
  2. If the app runs in Docker, set DOCKER_INTERNAL_URL (e.g. http://host.docker.internal) so the container reaches the host, and start Ollama with OLLAMA_HOST=0.0.0.0.
  3. Check the server_address/port in config.ini — ensure the port matches the Ollama daemon (default 11434).
  4. Verify no firewall blocks the port and that the host is reachable (ping or curl from the same network the app runs in).

Example fix

// before: Ollama only listens on loopback, Docker can't reach it
$ ollama serve
// after
$ OLLAMA_HOST=0.0.0.0 ollama serve
// and in the container env
DOCKER_INTERNAL_URL=http://host.docker.internal
Defensive patterns

Strategy: validation

Validate before calling

import httpx

def ollama_reachable(host: str, timeout: float = 5.0) -> bool:
    try:
        r = httpx.get(f"{host}/api/tags", timeout=timeout)
        return r.status_code == 200
    except httpx.HTTPError:
        return False

# before creating the Provider:
# if not ollama_reachable('http://localhost:11434'): start_ollama()

Type guard

def is_connect_error(e: BaseException) -> bool:
    import httpx
    return isinstance(e, httpx.ConnectError)

Try / catch

try:
    res = provider.respond(history)
except Exception as e:
    if 'Ollama connection failed' in str(e):
        print('Start Ollama: ollama serve, then verify: curl http://localhost:11434/api/tags')
        # optionally retry after starting the daemon
    else:
        raise

Prevention

When it happens

Trigger: client.chat(stream=True) fails at the transport layer: Ollama not installed/running (no daemon on 11434), wrong host/port in config (server_address), or — when is_local and running inside Docker — the internal URL (DOCKER_INTERNAL_URL, e.g. host.docker.internal) plus port is unreachable from the container.

Common situations: Fresh machine where Ollama was never started ('ollama serve'); Docker container trying to reach localhost:11434 which is the container itself, not the host; Ollama bound to 127.0.0.1 only while the client is in another container (needs OLLAMA_HOST=0.0.0.0); wrong port configured; firewall blocking the port.

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 Fosowl/agenticSeek@ae57a23577 (2026-08-30). Data as JSON: /api/errors/64d3f00ecb08d0dd. Report an issue: GitHub.