{"record":{"id":"b3fa7cab01aa4fdc","repo":"Mintplex-Labs/anything-llm","slug":"lmstudio-service-could-not-be-reached-is-lmstudio","errorCode":null,"errorMessage":"LMStudio service could not be reached. Is LMStudio running?","messagePattern":"LMStudio service could not be reached\\. Is LMStudio running\\?","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/EmbeddingEngines/lmstudio/index.js","lineNumber":51,"sourceCode":"    return await this.lmstudio.models\n      .list()\n      .then((res) => res?.data?.length > 0)\n      .catch((e) => {\n        this.log(e.message);\n        return false;\n      });\n  }\n\n  async embedTextInput(textInput) {\n    const result = await this.embedChunks(\n      Array.isArray(textInput) ? textInput : [textInput]\n    );\n    return result?.[0] || [];\n  }\n\n  async embedChunks(textChunks = []) {\n    if (!(await this.#isAlive()))\n      throw new Error(\n        `LMStudio service could not be reached. Is LMStudio running?`\n      );\n\n    this.log(\n      `Embedding ${textChunks.length} chunks of text with ${this.model}.`\n    );\n\n    // LMStudio will drop all queued requests now? So if there are many going on\n    // we need to do them sequentially or else only the first resolves and the others\n    // get dropped or go unanswered >:(\n    let results = [];\n    let hasError = false;\n    for (const [idx, chunk] of textChunks.entries()) {\n      if (hasError) break;\n      results.push(\n        await this.lmstudio.embeddings\n          .create({\n            model: this.model,","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/EmbeddingEngines/lmstudio/index.js#L33-L69","documentation":"Thrown at the top of LMStudioEmbedder.embedChunks when the private #isAlive() check fails. #isAlive() calls GET /models on the LM Studio server and requires a non-empty model list, so this error fires both when the server is unreachable (connection refused, logged then false) AND when LM Studio is running but has zero models loaded.","triggerScenarios":"LM Studio app open but the local server not started (Developer tab toggle off); server on a different port than EMBEDDING_BASE_PATH; server running with no model loaded (fresh headless launch without --load), so models.list() returns [] and data.length > 0 is false; firewall/loopback issues; LM Studio crashed between document uploads.","commonSituations":"'Is LMStudio running?' during first-run setups where the UI is open but the server was never started; headless/CLI LM Studio instances with no default model; embedding after a machine reboot where LM Studio did not auto-start its server.","solutions":["Open LM Studio and start the local server; confirm it prints the same URL as EMBEDDING_BASE_PATH","Load at least one model in LM Studio — the health check requires the /models list to be non-empty","curl the /models endpoint yourself (curl http://localhost:1234/v1/models) to distinguish 'unreachable' from 'no models'","If the port differs from 1234, update EMBEDDING_BASE_PATH accordingly","Retry the embed once the server reports at least one loaded model"],"exampleFix":"# LM Studio not serving any model -> health check fails even though app is running:\n# before\nlms load --verbose   # (or UI: nothing loaded, server on)\n\n# after\nlms load nomic-embed-text-v1.5 --verbose\ncurl http://localhost:1234/v1/models   # must return non-empty data[]","handlingStrategy":"try-catch","validationCode":"// Mirror the internal #isAlive() contract: reachable AND at least one model loaded\nconst { OpenAI } = require(\"openai\");\nasync function lmStudioAlive(basePath) {\n  const openai = new OpenAI({ baseURL: basePath, apiKey: process.env.LMSTUDIO_AUTH_TOKEN ?? null });\n  try {\n    const res = await openai.models.list();\n    return (res?.data?.length ?? 0) > 0;\n  } catch (e) {\n    console.error(\"LMStudio unreachable:\", e.message);\n    return false;\n  }\n}\nif (!(await lmStudioAlive(process.env.EMBEDDING_BASE_PATH))) {\n  // show 'start LM Studio server and load a model' instead of attempting the embed\n}","typeGuard":null,"tryCatchPattern":"try {\n  const vectors = await embedder.embedTextInput(text);\n} catch (e) {\n  if (e.message.includes(\"LMStudio service could not be reached\")) {\n    // two distinct causes: server down (connection refused in logs) or zero models loaded\n    // start the LM Studio server AND load a model, then retry — the state can change, so retry is valid\n  } else throw e;\n}","preventionTips":["Remember the health check requires a NON-EMPTY model list — LM Studio running with no model loaded still fails","Start LM Studio's local server (Developer tab) and load the embedding model before embedding documents","In scripts, probe GET {EMBEDDING_BASE_PATH}/models first and fail with a clear message"],"tags":["lmstudio","local-server","connection-refused","health-check","embeddings"],"backgroundTag":"connection-refused","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}