Fosowl/agenticSeek · error · Exception

LM Studio returned empty response

Error message

LM Studio returned empty response

What it means

After a 200 response, lm_studio_fn checks response.text.strip() and raises this if the body is completely empty. A 200 with no body from LM Studio is treated as a failure since no choices/content can be extracted.

Source

Thrown at sources/llm_provider.py:389

            # 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

        except requests.exceptions.Timeout:

View on GitHub (pinned to ae57a23577)

Solutions

  1. Retry the request — a single empty 200 is often transient
  2. Check LM Studio server logs for OOM or generation crash at that timestamp
  3. Reduce context/max_tokens or load a smaller quant so the model fits in VRAM/RAM
  4. Remove any local proxy between the client and LM Studio and retry
  5. Update LM Studio to the latest version; older builds had empty-response bugs

Example fix

// before
content = provider.lm_studio_fn(history)
// after
for attempt in range(3):
    try:
        content = provider.lm_studio_fn(history)
        break
    except Exception as e:
        if "empty response" in str(e) and attempt < 2:
            time.sleep(2)
            continue
        raise
Defensive patterns

Strategy: retry

Try / catch

for attempt in range(3):
    try:
        content = provider.lm_studio_fn(history)
        break
    except Exception as e:
        if "empty response" in str(e) and attempt < 2:
            time.sleep(1 + attempt)
            continue
        raise

Prevention

When it happens

Trigger: LM Studio returns HTTP 200 but an empty body — typically a server-side generation glitch, a proxy stripping the body, or an interrupted response on the local server.

Common situations: LM Studio crashed mid-request while still returning 200; intermediate proxy/antivirus tooling emptying the response; extremely low max_tokens or resource exhaustion (OOM) killing generation.

Related errors


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