{"record":{"id":"64d3f00ecb08d0dd","repo":"Fosowl/agenticSeek","slug":"ollama-connection-failed-at-host-check-if-the","errorCode":null,"errorMessage":"\nOllama connection failed at {host}. Check if the server is running.","messagePattern":"\nOllama connection failed at (.+?)\\. Check if the server is running\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/llm_provider.py","lineNumber":189,"sourceCode":"        if self.is_local:\n            server_port = self.server_address.split(\":\")[-1] if \":\" in str(self.server_address) else \"11434\"\n            host = f\"{self.internal_url}:{server_port}\"\n        else:\n            host = f\"http://{self.server_address}\"\n        client = OllamaClient(host=host)\n\n        try:\n            stream = client.chat(\n                model=self.model,\n                messages=history,\n                stream=True,\n            )\n            for chunk in stream:\n                if verbose:\n                    print(chunk[\"message\"][\"content\"], end=\"\", flush=True)\n                thought += chunk[\"message\"][\"content\"]\n        except httpx.ConnectError as e:\n            raise Exception(\n                f\"\\nOllama connection failed at {host}. Check if the server is running.\"\n            ) from e\n        except Exception as e:\n            if hasattr(e, 'status_code') and e.status_code == 404:\n                animate_thinking(f\"Downloading {self.model}...\")\n                client.pull(self.model)\n                return self.ollama_fn(history, verbose)\n            if \"refused\" in str(e).lower():\n                raise Exception(\n                    f\"Ollama connection refused at {host}. Is the server running?\"\n                ) from e\n            raise e\n\n        return thought\n\n    def huggingface_fn(self, history, verbose=False):\n        \"\"\"\n        Use huggingface to generate text.","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/Fosowl/agenticSeek/blob/ae57a2357745a9706cb12d0fd76d954c84d166fa/sources/llm_provider.py#L171-L207","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Start the Ollama server: run 'ollama serve' (or start the desktop app) and verify with curl http://localhost:11434/api/tags.","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.","Check the server_address/port in config.ini — ensure the port matches the Ollama daemon (default 11434).","Verify no firewall blocks the port and that the host is reachable (ping or curl from the same network the app runs in)."],"exampleFix":"// before: Ollama only listens on loopback, Docker can't reach it\n$ ollama serve\n// after\n$ OLLAMA_HOST=0.0.0.0 ollama serve\n// and in the container env\nDOCKER_INTERNAL_URL=http://host.docker.internal","handlingStrategy":"validation","validationCode":"import httpx\n\ndef ollama_reachable(host: str, timeout: float = 5.0) -> bool:\n    try:\n        r = httpx.get(f\"{host}/api/tags\", timeout=timeout)\n        return r.status_code == 200\n    except httpx.HTTPError:\n        return False\n\n# before creating the Provider:\n# if not ollama_reachable('http://localhost:11434'): start_ollama()","typeGuard":"def is_connect_error(e: BaseException) -> bool:\n    import httpx\n    return isinstance(e, httpx.ConnectError)","tryCatchPattern":"try:\n    res = provider.respond(history)\nexcept Exception as e:\n    if 'Ollama connection failed' in str(e):\n        print('Start Ollama: ollama serve, then verify: curl http://localhost:11434/api/tags')\n        # optionally retry after starting the daemon\n    else:\n        raise","preventionTips":["Start the Ollama daemon (ollama serve) before running the app; add a healthcheck against /api/tags.","In Docker, set DOCKER_INTERNAL_URL and run Ollama with OLLAMA_HOST=0.0.0.0 so containers can reach the host.","Verify the port in config.ini matches the daemon (default 11434).","Check firewall rules for the Ollama port when connecting across machines."],"tags":["network","ollama","connection","docker"],"backgroundTag":"connection-refused","analyzedSha":"ae57a2357745a9706cb12d0fd76d954c84d166fa","analyzedAt":"2026-08-30T02:49:05.834Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}