{"record":{"id":"0687037be7aeb50e","repo":"Mintplex-Labs/anything-llm","slug":"omlx-must-have-a-valid-model-set","errorCode":null,"errorMessage":"OMLX must have a valid model set.","messagePattern":"OMLX must have a valid model set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"server/utils/AiProviders/omlx/index.js","lineNumber":30,"sourceCode":" * OMLX (oMLX) is an OpenAI-compatible MLX inference server for Apple Silicon.\n * https://github.com/jundot/omlx\n */\nclass OMLXLLM {\n  /** @see OMLXLLM.cacheContextWindows */\n  static modelContextWindows = {};\n\n  constructor(embedder = null, modelPreference = null) {\n    if (!process.env.OMLX_LLM_BASE_PATH)\n      throw new Error(\"No OMLX API Base Path was set.\");\n\n    this.className = \"OMLXLLM\";\n    this.omlx = new OpenAIApi({\n      baseURL: parseOMLXBasePath(process.env.OMLX_LLM_BASE_PATH),\n      apiKey: process.env.OMLX_LLM_API_KEY || null,\n    });\n\n    this.model = modelPreference || process.env.OMLX_LLM_MODEL_PREF;\n    if (!this.model) throw new Error(\"OMLX must have a valid model set.\");\n\n    this.embedder = embedder ?? new NativeEmbedder();\n    this.defaultTemp = 0.7;\n\n    // Lazy load the limits to avoid blocking the main thread on cacheContextWindows\n    this.limits = null;\n\n    OMLXLLM.cacheContextWindows(true);\n    this.#log(`initialized with model: ${this.model}`);\n  }\n\n  #log(text, ...args) {\n    console.log(`\\x1b[32m[OMLX]\\x1b[0m ${text}`, ...args);\n  }\n\n  static #slog(text, ...args) {\n    console.log(`\\x1b[32m[OMLX]\\x1b[0m ${text}`, ...args);\n  }","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/omlx/index.js#L12-L48","documentation":"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.","triggerScenarios":"Constructing OMLXLLM with no modelPreference argument while OMLX_LLM_MODEL_PREF is unset/empty.","commonSituations":"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.","solutions":["Set OMLX_LLM_MODEL_PREF to a valid oMLX model id, or pass modelPreference when constructing OMLXLLM.","Re-select the model in the AnythingLLM UI and save.","Restart the server after editing .env.","Verify the model id matches one returned by the oMLX /v1/models endpoint."],"exampleFix":"// before\nthis.model = modelPreference || process.env.OMLX_LLM_MODEL_PREF;\nif (!this.model) throw new Error('OMLX must have a valid model set.');\n\n// caller side - validate before constructing\nconst model = modelPreference || process.env.OMLX_LLM_MODEL_PREF;\nif (!model) throw new Error('Cannot start OMLX: specify a model id.');\nreturn new OMLXLLM(embedder, model);","handlingStrategy":"validation","validationCode":"const model = modelPreference || process.env.OMLX_LLM_MODEL_PREF;\nif (!model || typeof model !== 'string' || !model.trim())\n  throw new Error('OMLX requires a model id (set OMLX_LLM_MODEL_PREF).');","typeGuard":"const isNonEmptyModel = (m) => typeof m === 'string' && m.trim().length > 0;","tryCatchPattern":null,"preventionTips":["Resolve and validate the model in the provider factory before constructing OMLXLLM.","Persist the workspace model preference so it is never blank.","Cross-check the id against oMLX /v1/models after first configuration."],"tags":["omlx","configuration","validation"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}