{"record":{"id":"756243b5f4dd29ed","repo":"nikivdev/code","slug":"lm-studio-returned-status","errorCode":null,"errorMessage":"LM Studio returned status {}: {}","messagePattern":"LM Studio returned status (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lmstudio.rs","lineNumber":67,"sourceCode":"    let url = format!(\"http://localhost:{port}/v1/chat/completions\");\n\n    let body = ChatRequest {\n        model: model.to_string(),\n        messages: vec![ChatMessage {\n            role: \"user\".to_string(),\n            content: prompt.to_string(),\n        }],\n        temperature: 0.1, // Low temperature for deterministic task matching\n    };\n\n    let resp = client\n        .post(&url)\n        .json(&body)\n        .send()\n        .with_context(|| format!(\"failed to connect to LM Studio at localhost:{port}\"))?;\n\n    if !resp.status().is_success() {\n        anyhow::bail!(\n            \"LM Studio returned status {}: {}\",\n            resp.status(),\n            resp.text().unwrap_or_default()\n        );\n    }\n\n    let text_body = resp.text().context(\"failed to read LM Studio response\")?;\n    let parsed: ChatResponse =\n        serde_json::from_str(&text_body).context(\"failed to parse LM Studio response\")?;\n\n    let text = parsed\n        .choices\n        .first()\n        .and_then(|c| c.message.as_ref())\n        .map(|m| m.content.trim().to_string())\n        .unwrap_or_default();\n\n    Ok(text)","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/lmstudio.rs#L49-L85","documentation":"quick_prompt sends a JSON POST to the local LM Studio server. If the HTTP response status is not a success (4xx/5xx), it bails including the status code and the response body text. Connection failures are a separate error ('failed to connect...'); this one means the server answered but rejected or failed the request.","triggerScenarios":"Calling quick_prompt when LM Studio returns e.g. 404 (wrong path/model endpoint), 400 (malformed request body/invalid model), or 500 (server-side model load failure).","commonSituations":"LM Studio server running but the requested model is not loaded or the model id doesn't match; API server started on a different path/version; prompt exceeding context limits causing a 4xx/5xx; wrong port hitting a different service.","solutions":["Check the response body echoed in the error for the server's reason (e.g. 'model not found')","Load the intended model in LM Studio and use its exact model id in the request","Confirm the URL/port matches the LM Studio API server (default http://localhost:1234/v1/...) and restart/retry"],"exampleFix":"// before (model id guess)\nlet body = json!({\"model\": \"llama\", \"prompt\": prompt});\n// after\nlet body = json!({\"model\": \"local-model\", \"prompt\": prompt}); // exact id from LM Studio's loaded model","handlingStrategy":"try-catch","validationCode":"let port = 1234;\nlet healthy = reqwest::blocking::get(format!(\"http://localhost:{port}/v1/models\"))\n    .and_then(|r| async { r.error_for_status() })\n    .is_ok();\nif !healthy { eprintln!(\"LM Studio API not healthy on port {port}\"); }","typeGuard":"fn is_success(resp: &reqwest::Response) -> bool { resp.status().is_success() }","tryCatchPattern":"match quick_prompt(prompt).await {\n    Err(e) if e.to_string().contains(\"LM Studio returned status\") => {\n        eprintln!(\"Inspect status/body in the error; check the model id and that the model is loaded\");\n    }\n    other => other?,\n}","preventionTips":["Load the target model in LM Studio and use its exact model id in requests","Health-check /v1/models before prompting; pin the port and path","Retry on 5xx with backoff; treat 4xx as a request/config bug to fix, not retry"],"tags":["http","lmstudio","api","network"],"backgroundTag":"http-error-response","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}