{"record":{"id":"e509c949fed75017","repo":"Fosowl/agenticSeek","slug":"cannot-connect-to-lm-studio-at-route-start-che","errorCode":null,"errorMessage":"Cannot connect to LM Studio at {route_start} - check if server is running","messagePattern":"Cannot connect to LM Studio at (.+?) - check if server is running","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/llm_provider.py","lineNumber":410,"sourceCode":"            except ValueError as json_err:\n                raise Exception(f\"Invalid JSON from LM Studio: {response.text[:200]}\") from json_err\n\n            if verbose:\n                print(\"Response from LM Studio:\", result)\n            choices = result.get(\"choices\", [])\n            if not choices:\n                raise Exception(f\"No choices in LM Studio response: {result}\")\n\n            message = choices[0].get(\"message\", {})\n            content = message.get(\"content\", \"\")\n            if not content:\n                raise Exception(f\"Empty content in LM Studio response: {result}\")\n            return content\n\n        except requests.exceptions.Timeout:\n            raise Exception(\"LM Studio request timed out - check if server is responsive\")\n        except requests.exceptions.ConnectionError:\n            raise Exception(f\"Cannot connect to LM Studio at {route_start} - check if server is running\")\n        except requests.exceptions.RequestException as e:\n            raise Exception(f\"HTTP request failed: {str(e)}\") from e\n        except Exception as e:\n            if \"LM Studio\" in str(e):\n                raise  # Re-raise our custom exceptions\n            raise Exception(f\"Unexpected error: {str(e)}\") from e\n\n    def openrouter_fn(self, history, verbose=False):\n        \"\"\"\n        Use OpenRouter API to generate text.\n        \"\"\"\n        client = OpenAI(api_key=self.api_key, base_url=\"https://openrouter.ai/api/v1\")\n        if self.is_local:\n            # This case should ideally not be reached if unsafe_providers is set correctly\n            # and is_local is False in config for openrouter\n            raise Exception(\"OpenRouter is not available for local use. Change config.ini\")\n        try:\n            response = client.chat.completions.create(","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/Fosowl/agenticSeek/blob/ae57a2357745a9706cb12d0fd76d954c84d166fa/sources/llm_provider.py#L392-L428","documentation":"lm_studio_fn catches requests.exceptions.ConnectionError and raises this message including the target URL. It means no service was listening at route_start — the LM Studio server isn't running, or host/port are wrong.","triggerScenarios":"TCP connection to route_start refused/unreachable: LM Studio 'Start Server' not enabled, wrong port in config.ini, server bound to a different interface (e.g. 127.0.0.1 vs container host), or server crashed.","commonSituations":"Forgot to start the local server in LM Studio; running the client inside Docker where 'localhost' is the container, not the host (need host.docker.internal); firewall blocking the port; config.ini port mismatch with LM Studio's configured port.","solutions":["Start the LM Studio server (Developer tab -> Start Server, or `lms server start`) and confirm the port","Match the URL in config.ini to the server's actual host:port (default http://localhost:1234)","If the app runs in Docker (self.in_docker), use host.docker.internal or the host's LAN IP instead of localhost","Test connectivity: curl http://<host>:<port>/v1/models should return the loaded model list","Check firewall rules allow the port if accessing across machines/containers"],"exampleFix":"// before (client inside Docker)\nurl = \"http://localhost:1234/v1/chat/completions\"\n// after\nurl = \"http://host.docker.internal:1234/v1/chat/completions\"","handlingStrategy":"validation","validationCode":"import socket, requests\ndef assert_lm_studio_reachable(url):\n    assert url.rstrip('/').endswith('/v1/chat/completions'), \"Point at /v1/chat/completions\"\n    try:\n        requests.get(url.rsplit('/v1/', 1)[0] + \"/v1/models\", timeout=3)\n    except requests.exceptions.ConnectionError:\n        raise RuntimeError(f\"LM Studio not reachable at {url} — start the server and fix host/port\")","typeGuard":null,"tryCatchPattern":"try:\n    content = provider.lm_studio_fn(history)\nexcept Exception as e:\n    if \"Cannot connect to LM Studio\" in str(e):\n        start_lm_studio_server()\n        content = provider.lm_studio_fn(history)\n    else:\n        raise","preventionTips":["Start the LM Studio server (lms server start) before running the app","Inside Docker use host.docker.internal or host LAN IP, never localhost","Verify with curl /v1/models at startup and fail fast with a clear message","Pin the port in both config.ini and LM Studio settings so they can't drift"],"tags":["connection-refused","lm-studio","network","docker","local-server"],"backgroundTag":"connection-refused","analyzedSha":"ae57a2357745a9706cb12d0fd76d954c84d166fa","analyzedAt":"2026-08-30T02:49:05.834Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}