Mintplex-Labs/anything-llm · critical · Error
LMStudio must have a valid model set.
Error message
LMStudio must have a valid model set.
What it means
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.
Source
Thrown at server/utils/agents/aibitat/providers/lmstudio.js:27
parseLMStudioBasePath,
} = require("../../../AiProviders/lmStudio/index.js");
/**
* The agent provider for the LMStudio.
* Supports true OpenAI-compatible tool calling when the model supports it,
* falling back to the UnTooled prompt-based approach otherwise.
*/
class LMStudioProvider extends InheritMultiple([Provider, UnTooled]) {
model;
/**
* @param {{model?: string}} config
*/
constructor(config = {}) {
super();
this.providerTag = "lmstudio";
const model = config?.model || process.env.LMSTUDIO_MODEL_PREF;
if (!model) throw new Error("LMStudio must have a valid model set.");
const apiKey = process.env.LMSTUDIO_AUTH_TOKEN ?? null;
const client = new OpenAI({
baseURL: parseLMStudioBasePath(process.env.LMSTUDIO_BASE_PATH),
apiKey,
});
this._client = client;
this.model = model;
this.verbose = true;
this._supportsToolCalling = null;
}
get client() {
return this._client;
}
get supportsAgentStreaming() {View on GitHub (pinned to 526360e320)
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.
Example fix
// before (env missing) // LMSTUDIO_MODEL_PREF= const p = new LMStudioProvider(); // after (.env) // LMSTUDIO_MODEL_PREF=meta-llama/Meta-Llama-3-8B-Instruct const p = new LMStudioProvider();
Defensive patterns
Strategy: validation
Validate before calling
// Resolve the model BEFORE constructing the provider.
const model = config?.model || process.env.LMSTUDIO_MODEL_PREF;
if (!model)
throw new Error(
"Set LMSTUDIO_MODEL_PREF (or pass config.model) before creating LMStudioProvider."
); Type guard
/** @param {unknown} v @returns {v is string} */
function isNonEmptyString(v) {
return typeof v === "string" && v.trim().length > 0;
} Try / catch
try {
return new LMStudioProvider(config);
} catch (e) {
if (/valid model set/.test(e.message)) {
// prompt the user for a model id, then retry construction
throw new Error("Please choose an LM Studio model before starting the agent.");
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- OMLX must have a valid model set.
- LMStudio base path must be provided to use agents.
- GenericOpenAI must have a valid base path to use for the api
- No Lemonade API Base Path was set.
- No embedding base path was set.
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/0141f34d773089cb.
Report an issue: GitHub.