Fosowl/agenticSeek · error · Exception

Cannot connect to LM Studio at {route_start} - check if serv

Error message

Cannot connect to LM Studio at {route_start} - check if server is running

What it means

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.

Source

Thrown at sources/llm_provider.py:410

            except ValueError as json_err:
                raise Exception(f"Invalid JSON from LM Studio: {response.text[:200]}") from json_err

            if verbose:
                print("Response from LM Studio:", result)
            choices = result.get("choices", [])
            if not choices:
                raise Exception(f"No choices in LM Studio response: {result}")

            message = choices[0].get("message", {})
            content = message.get("content", "")
            if not content:
                raise Exception(f"Empty content in LM Studio response: {result}")
            return content

        except requests.exceptions.Timeout:
            raise Exception("LM Studio request timed out - check if server is responsive")
        except requests.exceptions.ConnectionError:
            raise Exception(f"Cannot connect to LM Studio at {route_start} - check if server is running")
        except requests.exceptions.RequestException as e:
            raise Exception(f"HTTP request failed: {str(e)}") from e
        except Exception as e:
            if "LM Studio" in str(e):
                raise  # Re-raise our custom exceptions
            raise Exception(f"Unexpected error: {str(e)}") from e

    def openrouter_fn(self, history, verbose=False):
        """
        Use OpenRouter API to generate text.
        """
        client = OpenAI(api_key=self.api_key, base_url="https://openrouter.ai/api/v1")
        if self.is_local:
            # This case should ideally not be reached if unsafe_providers is set correctly
            # and is_local is False in config for openrouter
            raise Exception("OpenRouter is not available for local use. Change config.ini")
        try:
            response = client.chat.completions.create(

View on GitHub (pinned to ae57a23577)

Solutions

  1. Start the LM Studio server (Developer tab -> Start Server, or `lms server start`) and confirm the port
  2. Match the URL in config.ini to the server's actual host:port (default http://localhost:1234)
  3. If the app runs in Docker (self.in_docker), use host.docker.internal or the host's LAN IP instead of localhost
  4. Test connectivity: curl http://<host>:<port>/v1/models should return the loaded model list
  5. Check firewall rules allow the port if accessing across machines/containers

Example fix

// before (client inside Docker)
url = "http://localhost:1234/v1/chat/completions"
// after
url = "http://host.docker.internal:1234/v1/chat/completions"
Defensive patterns

Strategy: validation

Validate before calling

import socket, requests
def assert_lm_studio_reachable(url):
    assert url.rstrip('/').endswith('/v1/chat/completions'), "Point at /v1/chat/completions"
    try:
        requests.get(url.rsplit('/v1/', 1)[0] + "/v1/models", timeout=3)
    except requests.exceptions.ConnectionError:
        raise RuntimeError(f"LM Studio not reachable at {url} — start the server and fix host/port")

Try / catch

try:
    content = provider.lm_studio_fn(history)
except Exception as e:
    if "Cannot connect to LM Studio" in str(e):
        start_lm_studio_server()
        content = provider.lm_studio_fn(history)
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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/e509c949fed75017. Report an issue: GitHub.