Mintplex-Labs/anything-llm · critical · Error

OMLX must have a valid model set.

Error message

OMLX must have a valid model set.

What it means

Synchronous constructor guard thrown immediately after the base-path check. The model is resolved as modelPreference || process.env.OMLX_LLM_MODEL_PREF; if both are falsy the instance cannot target a model. Unlike OpenAI there is no default fallback, so this throws.

Source

Thrown at server/utils/AiProviders/omlx/index.js:30

 * OMLX (oMLX) is an OpenAI-compatible MLX inference server for Apple Silicon.
 * https://github.com/jundot/omlx
 */
class OMLXLLM {
  /** @see OMLXLLM.cacheContextWindows */
  static modelContextWindows = {};

  constructor(embedder = null, modelPreference = null) {
    if (!process.env.OMLX_LLM_BASE_PATH)
      throw new Error("No OMLX API Base Path was set.");

    this.className = "OMLXLLM";
    this.omlx = new OpenAIApi({
      baseURL: parseOMLXBasePath(process.env.OMLX_LLM_BASE_PATH),
      apiKey: process.env.OMLX_LLM_API_KEY || null,
    });

    this.model = modelPreference || process.env.OMLX_LLM_MODEL_PREF;
    if (!this.model) throw new Error("OMLX must have a valid model set.");

    this.embedder = embedder ?? new NativeEmbedder();
    this.defaultTemp = 0.7;

    // Lazy load the limits to avoid blocking the main thread on cacheContextWindows
    this.limits = null;

    OMLXLLM.cacheContextWindows(true);
    this.#log(`initialized with model: ${this.model}`);
  }

  #log(text, ...args) {
    console.log(`\x1b[32m[OMLX]\x1b[0m ${text}`, ...args);
  }

  static #slog(text, ...args) {
    console.log(`\x1b[32m[OMLX]\x1b[0m ${text}`, ...args);
  }

View on GitHub (pinned to 526360e320)

Solutions

  1. Set OMLX_LLM_MODEL_PREF to a valid oMLX model id, or pass modelPreference when constructing OMLXLLM.
  2. Re-select the model in the AnythingLLM UI and save.
  3. Restart the server after editing .env.
  4. Verify the model id matches one returned by the oMLX /v1/models endpoint.

Example fix

// before
this.model = modelPreference || process.env.OMLX_LLM_MODEL_PREF;
if (!this.model) throw new Error('OMLX must have a valid model set.');

// caller side - validate before constructing
const model = modelPreference || process.env.OMLX_LLM_MODEL_PREF;
if (!model) throw new Error('Cannot start OMLX: specify a model id.');
return new OMLXLLM(embedder, model);
Defensive patterns

Strategy: validation

Validate before calling

const model = modelPreference || process.env.OMLX_LLM_MODEL_PREF;
if (!model || typeof model !== 'string' || !model.trim())
  throw new Error('OMLX requires a model id (set OMLX_LLM_MODEL_PREF).');

Type guard

const isNonEmptyModel = (m) => typeof m === 'string' && m.trim().length > 0;

Prevention

When it happens

Trigger: Constructing OMLXLLM with no modelPreference argument while OMLX_LLM_MODEL_PREF is unset/empty.

Common situations: Model field left blank in the provider UI; env var cleared; programmatic instantiation that forgets the second argument; model preference not persisted for the workspace.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/0687037be7aeb50e. Report an issue: GitHub.