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 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.

Solutions

  1. 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
  2. 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
  3. Confirm LMSTUDIO_BASE_PATH points at the running LM Studio server and LMSTUDIO_AUTH_TOKEN matches if the server requires auth

Example fix

# before
# LMSTUDIO_MODEL_PREF is unset -> constructor throws
LMSTUDIO_BASE_PATH=http://localhost:1234/v1

# after (id must match LM Studio's loaded model exactly)
LMSTUDIO_MODEL_PREF=qwen2.5-7b-instruct
LMSTUDIO_BASE_PATH=http://localhost:1234/v1
Defensive patterns

Strategy: validation

Validate before calling

// Validate before constructing the provider
const model = agentConfig?.model || process.env.LMSTUDIO_MODEL_PREF;
if (!model) {
  throw new Error("Select a model for the LM Studio agent (or set LMSTUDIO_MODEL_PREF)");
}
const provider = new LMStudioProvider({ model });

Type guard

function hasLmstudioModel(config) {
  return Boolean(config?.model || process.env.LMSTUDIO_MODEL_PREF);
}

Try / catch

try {
  provider = new LMStudioProvider(config);
} catch (error) {
  if (/valid model set/i.test(error.message)) {
    return respond("Configure LMSTUDIO_MODEL_PREF (a model loaded in LM Studio) and retry.");
  }
  throw error;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@f92433b4ea (2026-08-18). Data as JSON: /api/errors/0141f34d773089cb. Report an issue: GitHub.

Appendix: 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 f92433b4ea)