{"record":{"id":"7517ff8bb6234abf","repo":"Mintplex-Labs/anything-llm","slug":"litellm-must-have-a-valid-model-set","errorCode":null,"errorMessage":"LiteLLM must have a valid model set.","messagePattern":"LiteLLM must have a valid model set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"server/utils/AiProviders/liteLLM/index.js","lineNumber":26,"sourceCode":"} = require(\"../../helpers/chat/responses\");\n\nclass LiteLLM {\n  constructor(embedder = null, modelPreference = null) {\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    if (!process.env.LITE_LLM_BASE_PATH)\n      throw new Error(\n        \"LiteLLM must have a valid base path to use for the api.\"\n      );\n\n    this.className = \"LiteLLM\";\n    this.basePath = process.env.LITE_LLM_BASE_PATH;\n    this.openai = new OpenAIApi({\n      baseURL: this.basePath,\n      apiKey: process.env.LITE_LLM_API_KEY ?? null,\n    });\n    this.model = modelPreference ?? process.env.LITE_LLM_MODEL_PREF ?? null;\n\n    if (!this.model) throw new Error(\"LiteLLM must have a valid model set.\");\n    this.limits = {\n      history: this.promptWindowLimit() * 0.15,\n      system: this.promptWindowLimit() * 0.15,\n      user: this.promptWindowLimit() * 0.7,\n    };\n\n    this.embedder = embedder ?? new NativeEmbedder();\n    this.defaultTemp = 0.7;\n    this.log(`Inference API: ${this.basePath} Model: ${this.model}`);\n  }\n\n  log(text, ...args) {\n    console.log(`\\x1b[36m[${this.className}]\\x1b[0m ${text}`, ...args);\n  }\n\n  #appendContext(contextTexts = []) {\n    if (!contextTexts || !contextTexts.length) return \"\";\n    return (","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/liteLLM/index.js#L8-L44","documentation":"Thrown by the LiteLLM constructor when no model can be resolved. The constructor uses `modelPreference ?? process.env.LITE_LLM_MODEL_PREF ?? null`, meaning both the constructor argument and the env var must be nullish (null/undefined) for the error to fire. Note: `??` does NOT treat empty string as falsy, so an empty-string modelPreference would be used (and would not trigger this guard).","triggerScenarios":"Instantiating `new LiteLLM(embedder, model)` where model is null/undefined AND process.env.LITE_LLM_MODEL_PREF is unset. Common when getLLMProvider('litellm') is called with no workspace model selected.","commonSituations":"The LiteLLM provider was configured with a base path but the model name was never set. The LiteLLM proxy is configured but the user hasn't selected which model to route to. A workspace was created without specifying an LLM model.","solutions":["Set LITE_LLM_MODEL_PREF in .env to a model name that LiteLLM proxy knows how to route (e.g. 'gpt-3.5-turbo', 'anthropic/claude-2').","Select a model in the workspace LLM settings so the modelPreference argument is passed.","Check the LiteLLM proxy's /v1/models endpoint for available model identifiers."],"exampleFix":"// before: .env\nLITE_LLM_BASE_PATH='http://127.0.0.1:4000'\n\n// after\nLITE_LLM_BASE_PATH='http://127.0.0.1:4000'\nLITE_LLM_MODEL_PREF='gpt-3.5-turbo'","handlingStrategy":"validation","validationCode":"function validateLiteLLMModel(modelPreference) {\n  const model = modelPreference ?? process.env.LITE_LLM_MODEL_PREF ?? null;\n  if (!model) {\n    throw new Error(\n      'No LiteLLM model set. Set LITE_LLM_MODEL_PREF in .env or select a model in workspace settings.'\n    );\n  }\n  return model;\n}\n\nconst model = validateLiteLLMModel(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 LiteLLM(embedder, model);\n} catch (e) {\n  if (e.message.includes('valid model set')) {\n    console.error('Configure LITE_LLM_MODEL_PREF or select a model in workspace settings.');\n    return null;\n  }\n  throw e;\n}","preventionTips":["Query the LiteLLM proxy's /v1/models endpoint to list available models for selection.","Set LITE_LLM_MODEL_PREF in .env as a system-wide default.","Ensure the workspace model-selection UI requires a model before saving when LiteLLM is the provider."],"tags":["litellm","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"}