{"record":{"id":"530720b796d79656","repo":"Mintplex-Labs/anything-llm","slug":"no-lmstudio-api-base-path-was-set","errorCode":null,"errorMessage":"No LMStudio API Base Path was set.","messagePattern":"No LMStudio API Base Path was set\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/lmStudio/index.js","lineNumber":18,"sourceCode":"const { NativeEmbedder } = require(\"../../EmbeddingEngines/native\");\nconst {\n  handleDefaultStreamResponseV2,\n  formatChatHistory,\n} = require(\"../../helpers/chat/responses\");\nconst {\n  LLMPerformanceMonitor,\n} = require(\"../../helpers/chat/LLMPerformanceMonitor\");\nconst { OpenAI: OpenAIApi } = require(\"openai\");\n\n//  hybrid of openAi LLM chat completion for LMStudio\nclass LMStudioLLM {\n  /** @see LMStudioLLM.cacheContextWindows */\n  static modelContextWindows = {};\n\n  constructor(embedder = null, modelPreference = null) {\n    if (!process.env.LMSTUDIO_BASE_PATH)\n      throw new Error(\"No LMStudio API Base Path was set.\");\n\n    this.className = \"LMStudioLLM\";\n    const apiKey = process.env.LMSTUDIO_AUTH_TOKEN ?? null;\n    this.lmstudio = new OpenAIApi({\n      baseURL: parseLMStudioBasePath(process.env.LMSTUDIO_BASE_PATH), // here is the URL to your LMStudio instance\n      apiKey,\n    });\n\n    // Prior to LMStudio 0.2.17 the `model` param was not required and you could pass anything\n    // into that field and it would work. On 0.2.17 LMStudio introduced multi-model chat\n    // which now has a bug that reports the server model id as \"Loaded from Chat UI\"\n    // and any other value will crash inferencing. So until this is patched we will\n    // try to fetch the `/models` and have the user set it, or just fallback to \"Loaded from Chat UI\"\n    // which will not impact users with <v0.2.17 and should work as well once the bug is fixed.\n    this.model = modelPreference || process.env.LMSTUDIO_MODEL_PREF;\n    if (!this.model) throw new Error(\"LMStudio must have a valid model set.\");\n\n    this.embedder = embedder ?? new NativeEmbedder();","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/utils/AiProviders/lmStudio/index.js#L1-L36","documentation":"LMStudioLLM's constructor throws when LMSTUDIO_BASE_PATH is unset. LM Studio runs a local OpenAI-compatible server; the value is normalized by parseLMStudioBasePath() (lmStudio/index.js:368), which keeps only the origin and appends /v1 — so http://192.168.1.10:1234 becomes http://192.168.1.10:1234/v1. If the input is not parseable as a URL, it is passed through raw. LMSTUDIO_AUTH_TOKEN is optional (null default).","triggerScenarios":"Selecting LM Studio as the LLM provider while LMSTUDIO_BASE_PATH is missing from the server env — e.g., LM Studio's 'Local Server' not started (default port 1234), the var never added to .env, or Docker deployments where localhost must become host.docker.internal.","commonSituations":"User starts LM Studio the app but never clicks 'Start Server'; server bound in LM Studio to a different port; AnythingLLM in a container pointing at 127.0.0.1; providing a full path like http://localhost:1234/v1 (harmless — normalizer strips it) versus providing 'localhost:1234' without a scheme (URL() throws and the raw string is passed through, later breaking the SDK).","solutions":["In LM Studio: start the server (Developer → Start Server) and note the port (default 1234).","Set LMSTUDIO_BASE_PATH=http://127.0.0.1:1234 (include the http:// scheme) in backend .env.","Docker: use http://host.docker.internal:1234 or the host LAN IP.","If LM Studio's server requires CORS/auth, set LMSTUDIO_AUTH_TOKEN accordingly.","Restart AnythingLLM after saving env."],"exampleFix":"# before (.env)\nLMSTUDIO_MODEL_PREF=loaded-model\n\n# after (.env)\nLMSTUDIO_BASE_PATH=http://127.0.0.1:1234\nLMSTUDIO_MODEL_PREF=loaded-model","handlingStrategy":"validation","validationCode":"if (!process.env.LMSTUDIO_BASE_PATH) throw new Error(\"LMSTUDIO_BASE_PATH missing\");\ntry { new URL(process.env.LMSTUDIO_BASE_PATH); } catch { throw new Error(\"Include the scheme: http://127.0.0.1:1234\"); }","typeGuard":null,"tryCatchPattern":"try {\n  new LMStudioLLM(embedder, model);\n} catch (e) {\n  if (/LMStudio API Base Path/i.test(e.message)) return promptEnvSetup(\"LMSTUDIO_BASE_PATH\");\n  throw e;\n}","preventionTips":["Start LM Studio's local server and curl /v1/models before wiring AnythingLLM.","Always include http:// — parseLMStudioBasePath passes unparseable strings through raw, deferring the failure to the SDK.","Docker deployments: host.docker.internal:1234, not localhost.","Remember the normalizer keeps only the origin + /v1; extra sub-paths in the env var are discarded."],"tags":["lm-studio","anythingllm","local-llm","env-var","base-url","configuration"],"backgroundTag":"missing-base-url","analyzedSha":"f92433b4ea0598492a1e6645ea22addbb4dd1287","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}