Fosowl/agenticSeek · error · Exception

LM Studio returned status {response.status_code}: {response.

Error message

LM Studio returned status {response.status_code}: {response.text}

What it means

lm_studio_fn posts to the local LM Studio server (requests.post, timeout=30) and raises this when the HTTP status is not 200, including the status code and response body. It means LM Studio answered but rejected the request (bad model, malformed payload, server error).

Source

Thrown at sources/llm_provider.py:387

                url = f"{scheme}://{hostname}:{port}"
        else:
            # Normalize the address to ensure it has a scheme prefix
            addr = self.server_ip
            if "://" not in addr:
                addr = f"http://{addr}"
            url = addr
        route_start = f"{url}/v1/chat/completions"
        payload = {
            "messages": history,
            "temperature": 0.7,
            "max_tokens": 4096,
            "model": self.model
        }

        try:
            response = requests.post(route_start, json=payload, timeout=30)
            if response.status_code != 200:
                raise Exception(f"LM Studio returned status {response.status_code}: {response.text}")
            if not response.text.strip():
                raise Exception("LM Studio returned empty response")
            try:
                result = response.json()
            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

View on GitHub (pinned to ae57a23577)

Solutions

  1. Read the status code and body in the message: 404/400 usually means the model isn't loaded or the name is wrong
  2. Load the configured model in LM Studio (Developer tab -> Load Model) and verify the model identifier matches self.model
  3. Confirm the LM Studio server URL/port in config.ini matches the running server (default http://localhost:1234)
  4. Restart the LM Studio server if the body shows 500; check its logs
  5. Confirm you started the server with 'Start Server' enabled / `lms server start`

Example fix

// before
"model": "llama-3-8b"
// after
"model": "lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF"  # must match loaded model id
Defensive patterns

Strategy: retry

Validate before calling

def validate_lm_studio(url, model):
    import requests
    r = requests.get(f"{url}/v1/models", timeout=5)
    r.raise_for_status()
    ids = [m["id"] for m in r.json().get("data", [])]
    assert model in ids, f"Model '{model}' not loaded in LM Studio (loaded: {ids})"

Type guard

def is_lm_studio_models_payload(payload) -> bool:
    return isinstance(payload, dict) and isinstance(payload.get("data"), list)

Try / catch

try:
    content = provider.lm_studio_fn(history)
except Exception as e:
    m = re.search(r"status (\d+)", str(e))
    if m and m.group(1) in ("500", "503"):
        restart_lm_studio_and_retry()
    elif m and m.group(1).startswith("4"):
        fix_model_or_payload(str(e))
    else:
        raise

Prevention

When it happens

Trigger: POST to route_start returns any status != 200: 404 when the model is not loaded in LM Studio, 400 for malformed payload, 500 for server-side generation failure.

Common situations: Model name in config.ini doesn't match a model loaded in LM Studio; LM Studio server started without loading a model; wrong port/host in route_start; LM Studio version regression.

Related errors


AI-assisted analysis of Fosowl/agenticSeek@ae57a23577 (2026-08-30). Data as JSON: /api/errors/94cda7580e70a184. Report an issue: GitHub.