{"record":{"id":"3bcfb50bc62c06fa","repo":"Mintplex-Labs/anything-llm","slug":"no-lemonade-model-pref-was-set","errorCode":null,"errorMessage":"No Lemonade Model Pref was set.","messagePattern":"No Lemonade Model Pref was set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"server/utils/AiProviders/lemonade/index.js","lineNumber":17,"sourceCode":"const { NativeEmbedder } = require(\"../../EmbeddingEngines/native\");\nconst {\n  handleDefaultStreamResponseV2,\n  formatChatHistory,\n} = require(\"../../helpers/chat/responses\");\nconst {\n  LLMPerformanceMonitor,\n} = require(\"../../helpers/chat/LLMPerformanceMonitor\");\nconst { OpenAI: OpenAIApi } = require(\"openai\");\nconst { humanFileSize } = require(\"../../helpers\");\n\nclass LemonadeLLM {\n  constructor(embedder = null, modelPreference = null) {\n    if (!process.env.LEMONADE_LLM_BASE_PATH)\n      throw new Error(\"No Lemonade API Base Path was set.\");\n    if (!process.env.LEMONADE_LLM_MODEL_PREF && !modelPreference)\n      throw new Error(\"No Lemonade Model Pref was set.\");\n\n    this.className = \"LemonadeLLM\";\n    this.lemonade = new OpenAIApi({\n      baseURL: parseLemonadeServerEndpoint(\n        process.env.LEMONADE_LLM_BASE_PATH,\n        \"openai\"\n      ),\n      apiKey: process.env.LEMONADE_LLM_API_KEY || null,\n    });\n\n    this.model = modelPreference || process.env.LEMONADE_LLM_MODEL_PREF;\n    this.embedder = embedder ?? new NativeEmbedder();\n    this.defaultTemp = 0.7;\n\n    // We can establish here since we cannot dynamically curl the context window limit from the API.\n    this.limits = {\n      history: this.promptWindowLimit() * 0.15,\n      system: this.promptWindowLimit() * 0.15,","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/lemonade/index.js#L1-L35","documentation":"Thrown by the LemonadeLLM constructor when neither the LEMONADE_LLM_MODEL_PREF environment variable nor the modelPreference constructor argument is provided. The check uses `&&` (both must be missing), so providing either one satisfies it. The model is later resolved as `modelPreference || process.env.LEMONADE_LLM_MODEL_PREF`.","triggerScenarios":"Instantiating `new LemonadeLLM(embedder, model)` where the `model` argument is null/undefined/falsy AND process.env.LEMONADE_LLM_MODEL_PREF is also unset. This happens through getLLMProvider when the workspace has no model selected.","commonSituations":"Selecting the Lemonade provider in workspace settings without choosing a model from the dropdown. The Lemonade server was just started and hasn't reported any models to AnythingLLM's model-listing UI yet. The LEMONADE_LLM_MODEL_PREF env var was removed from .env during cleanup.","solutions":["Set LEMONADE_LLM_MODEL_PREF in .env to a model available on your Lemonade server.","Select a model in the workspace LLM configuration UI so modelPreference is passed to the constructor.","Use the Lemonade model-discovery endpoint to list available models and pick a valid identifier."],"exampleFix":"// before: .env — only base path is set\nLEMONADE_LLM_BASE_PATH='http://127.0.0.1:8000'\n\n// after: add model pref\nLEMONADE_LLM_BASE_PATH='http://127.0.0.1:8000'\nLEMONADE_LLM_MODEL_PREF='Llama-3.2-1B-Instruct-cuda'","handlingStrategy":"validation","validationCode":"function validateLemonadeModel(modelPreference) {\n  if (!process.env.LEMONADE_LLM_MODEL_PREF && !modelPreference) {\n    throw new Error(\n      'No Lemonade model set. Set LEMONADE_LLM_MODEL_PREF in .env or select a model in workspace settings.'\n    );\n  }\n  return modelPreference || process.env.LEMONADE_LLM_MODEL_PREF;\n}\n\nconst model = validateLemonadeModel(workspaceModel);","typeGuard":"/** @returns {model is string} */\nfunction isValidModelName(model) {\n  return typeof model === 'string' && model.trim().length > 0;\n}","tryCatchPattern":"try {\n  const llm = new LemonadeLLM(embedder, model);\n} catch (e) {\n  if (e.message.includes('Model Pref')) {\n    console.error('Select a Lemonade model in workspace settings or set LEMONADE_LLM_MODEL_PREF.');\n    return null;\n  }\n  throw e;\n}","preventionTips":["Use Lemonade's model-discovery API to populate the model dropdown in the UI.","Set a default LEMONADE_LLM_MODEL_PREF in .env as a fallback.","Validate that the selected model is still available on the Lemonade server at startup."],"tags":["lemonade","configuration","env-var","constructor","model-selection"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}