{"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/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/utils/agents/aibitat/providers/lmstudio.js#L9-L45","documentation":"LMStudioProvider's constructor throws synchronously when no model can be resolved: it checks config.model (per-workspace agent setting) and falls back to process.env.LMSTUDIO_MODEL_PREF; if both are falsy the provider cannot be built and throws 'LMStudio must have a valid model set.'. This is a configuration guard, not an API failure — the OpenAI-compatible client for LM Studio is constructed immediately after and needs a concrete model id for every chat call. Because it throws in the constructor, agent initialization fails before any request is made.","triggerScenarios":"Instantiating new LMStudioProvider({}) (or with an empty/undefined model) while LMSTUDIO_MODEL_PREF is unset, empty, or whitespace — e.g. the workspace agent skill was saved without selecting a model and the env var was never populated.","commonSituations":"Fresh install where LM Studio provider was picked but no default model env was written; the LM Studio server has no model loaded so the UI never returned a model list to pick from; .env edited by hand and the variable removed; model was unloaded in LM Studio and the stored pref was cleared.","solutions":["Load a model in LM Studio (Developer tab with the local server started) and set LMSTUDIO_MODEL_PREF to that exact model id, then restart the server","Or set the model per agent: new LMStudioProvider({ model: \"qwen2.5-7b-instruct\" }) / pick the model in the agent provider settings so config.model is non-empty","Confirm LMSTUDIO_BASE_PATH points at the running LM Studio server and LMSTUDIO_AUTH_TOKEN matches if the server requires auth"],"exampleFix":"# before\n# LMSTUDIO_MODEL_PREF is unset -> constructor throws\nLMSTUDIO_BASE_PATH=http://localhost:1234/v1\n\n# after (id must match LM Studio's loaded model exactly)\nLMSTUDIO_MODEL_PREF=qwen2.5-7b-instruct\nLMSTUDIO_BASE_PATH=http://localhost:1234/v1","handlingStrategy":"validation","validationCode":"// Validate before constructing the provider\nconst model = agentConfig?.model || process.env.LMSTUDIO_MODEL_PREF;\nif (!model) {\n  throw new Error(\"Select a model for the LM Studio agent (or set LMSTUDIO_MODEL_PREF)\");\n}\nconst provider = new LMStudioProvider({ model });","typeGuard":"function hasLmstudioModel(config) {\n  return Boolean(config?.model || process.env.LMSTUDIO_MODEL_PREF);\n}","tryCatchPattern":"try {\n  provider = new LMStudioProvider(config);\n} catch (error) {\n  if (/valid model set/i.test(error.message)) {\n    return respond(\"Configure LMSTUDIO_MODEL_PREF (a model loaded in LM Studio) and retry.\");\n  }\n  throw error;\n}","preventionTips":["Always pass an explicit { model } in agent config rather than relying on the env fallback","Start LM Studio's local server and load a model before saving the provider settings","Add a startup check: if provider is lmstudio and LMSTUDIO_MODEL_PREF is empty, warn immediately","Keep the env var in sync when you swap models in LM Studio"],"tags":["configuration","lmstudio","constructor","missing-model","env-var"],"backgroundTag":"missing-model-configuration","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"}