{"record":{"id":"0141f34d773089cb","repo":"Mintplex-Labs/anything-llm","slug":"lmstudio-must-have-a-valid-model-set-0141f3","errorCode":null,"errorMessage":"LMStudio must have a valid model set.","messagePattern":"LMStudio must have a valid model set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"server/utils/agents/aibitat/providers/lmstudio.js","lineNumber":27,"sourceCode":"  parseLMStudioBasePath,\n} = require(\"../../../AiProviders/lmStudio/index.js\");\n\n/**\n * The agent provider for the LMStudio.\n * Supports true OpenAI-compatible tool calling when the model supports it,\n * falling back to the UnTooled prompt-based approach otherwise.\n */\nclass LMStudioProvider extends InheritMultiple([Provider, UnTooled]) {\n  model;\n\n  /**\n   * @param {{model?: string}} config\n   */\n  constructor(config = {}) {\n    super();\n    this.providerTag = \"lmstudio\";\n    const model = config?.model || process.env.LMSTUDIO_MODEL_PREF;\n    if (!model) throw new Error(\"LMStudio must have a valid model set.\");\n\n    const apiKey = process.env.LMSTUDIO_AUTH_TOKEN ?? null;\n    const client = new OpenAI({\n      baseURL: parseLMStudioBasePath(process.env.LMSTUDIO_BASE_PATH),\n      apiKey,\n    });\n\n    this._client = client;\n    this.model = model;\n    this.verbose = true;\n    this._supportsToolCalling = null;\n  }\n\n  get client() {\n    return this._client;\n  }\n\n  get supportsAgentStreaming() {","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/agents/aibitat/providers/lmstudio.js#L9-L45","documentation":"LMStudioProvider's constructor (lmstudio.js:21-27) requires a model id from either config.model or the LMSTUDIO_MODEL_PREF environment variable and throws this if neither is set. LM Studio is a local OpenAI-compatible server, so the agent must be told which loaded model to target.","triggerScenarios":"Instantiating LMStudioProvider with an empty/undefined config.model while LMSTUDIO_MODEL_PREF is unset, or starting the server with a .env that is missing that variable.","commonSituations":"Fresh install where the model preference was never set, an env-var rename/removal, or the model id in LMSTUDIO_MODEL_PREF not matching a model loaded in the LM Studio GUI.","solutions":["Set LMSTUDIO_MODEL_PREF in .env to a model loaded in LM Studio (exact id).","Or pass { model: \"<id>\" } in the provider config at construction time.","Start the LM Studio local server and load the target model before sending requests.","Confirm LMSTUDIO_BASE_PATH points at the running server."],"exampleFix":"// before (env missing)\n// LMSTUDIO_MODEL_PREF=\nconst p = new LMStudioProvider();\n\n// after (.env)\n// LMSTUDIO_MODEL_PREF=meta-llama/Meta-Llama-3-8B-Instruct\nconst p = new LMStudioProvider();","handlingStrategy":"validation","validationCode":"// Resolve the model BEFORE constructing the provider.\nconst model = config?.model || process.env.LMSTUDIO_MODEL_PREF;\nif (!model)\n  throw new Error(\n    \"Set LMSTUDIO_MODEL_PREF (or pass config.model) before creating LMStudioProvider.\"\n  );","typeGuard":"/** @param {unknown} v @returns {v is string} */\nfunction isNonEmptyString(v) {\n  return typeof v === \"string\" && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  return new LMStudioProvider(config);\n} catch (e) {\n  if (/valid model set/.test(e.message)) {\n    // prompt the user for a model id, then retry construction\n    throw new Error(\"Please choose an LM Studio model before starting the agent.\");\n  }\n  throw e;\n}","preventionTips":["Always set LMSTUDIO_MODEL_PREF in .env alongside LMSTUDIO_BASE_PATH.","Load the target model in the LM Studio GUI before pointing agents at it.","Validate required env at server boot and fail fast with a clear message.","Keep a documented list of loaded model ids for users to pick from."],"tags":["lmstudio","config","env","model-selection","local-llm"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}