{"record":{"id":"94cda7580e70a184","repo":"Fosowl/agenticSeek","slug":"lm-studio-returned-status-response-status-code","errorCode":null,"errorMessage":"LM Studio returned status {response.status_code}: {response.text}","messagePattern":"LM Studio returned status (.+?): (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/llm_provider.py","lineNumber":387,"sourceCode":"                url = f\"{scheme}://{hostname}:{port}\"\n        else:\n            # Normalize the address to ensure it has a scheme prefix\n            addr = self.server_ip\n            if \"://\" not in addr:\n                addr = f\"http://{addr}\"\n            url = addr\n        route_start = f\"{url}/v1/chat/completions\"\n        payload = {\n            \"messages\": history,\n            \"temperature\": 0.7,\n            \"max_tokens\": 4096,\n            \"model\": self.model\n        }\n\n        try:\n            response = requests.post(route_start, json=payload, timeout=30)\n            if response.status_code != 200:\n                raise Exception(f\"LM Studio returned status {response.status_code}: {response.text}\")\n            if not response.text.strip():\n                raise Exception(\"LM Studio returned empty response\")\n            try:\n                result = response.json()\n            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","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/Fosowl/agenticSeek/blob/ae57a2357745a9706cb12d0fd76d954c84d166fa/sources/llm_provider.py#L369-L405","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the status code and body in the message: 404/400 usually means the model isn't loaded or the name is wrong","Load the configured model in LM Studio (Developer tab -> Load Model) and verify the model identifier matches self.model","Confirm the LM Studio server URL/port in config.ini matches the running server (default http://localhost:1234)","Restart the LM Studio server if the body shows 500; check its logs","Confirm you started the server with 'Start Server' enabled / `lms server start`"],"exampleFix":"// before\n\"model\": \"llama-3-8b\"\n// after\n\"model\": \"lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF\"  # must match loaded model id","handlingStrategy":"retry","validationCode":"def validate_lm_studio(url, model):\n    import requests\n    r = requests.get(f\"{url}/v1/models\", timeout=5)\n    r.raise_for_status()\n    ids = [m[\"id\"] for m in r.json().get(\"data\", [])]\n    assert model in ids, f\"Model '{model}' not loaded in LM Studio (loaded: {ids})\"","typeGuard":"def is_lm_studio_models_payload(payload) -> bool:\n    return isinstance(payload, dict) and isinstance(payload.get(\"data\"), list)","tryCatchPattern":"try:\n    content = provider.lm_studio_fn(history)\nexcept Exception as e:\n    m = re.search(r\"status (\\d+)\", str(e))\n    if m and m.group(1) in (\"500\", \"503\"):\n        restart_lm_studio_and_retry()\n    elif m and m.group(1).startswith(\"4\"):\n        fix_model_or_payload(str(e))\n    else:\n        raise","preventionTips":["Pre-flight check /v1/models contains the configured model before each session","Keep the LM Studio model id in config.ini exactly matching the loaded model","Check server logs on any non-200","Pin LM Studio versions in CI to avoid regressions"],"tags":["lm-studio","http","local-server","configuration"],"backgroundTag":"http-4xx-from-local-llm-server","analyzedSha":"ae57a2357745a9706cb12d0fd76d954c84d166fa","analyzedAt":"2026-08-30T02:49:05.834Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}