Mintplex-Labs/anything-llm · critical · Error
LiteLLM must have a valid model set.
Error message
LiteLLM must have a valid model set.
What it means
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).
Source
Thrown at server/utils/AiProviders/liteLLM/index.js:26
} = require("../../helpers/chat/responses");
class LiteLLM {
constructor(embedder = null, modelPreference = null) {
const { OpenAI: OpenAIApi } = require("openai");
if (!process.env.LITE_LLM_BASE_PATH)
throw new Error(
"LiteLLM must have a valid base path to use for the api."
);
this.className = "LiteLLM";
this.basePath = process.env.LITE_LLM_BASE_PATH;
this.openai = new OpenAIApi({
baseURL: this.basePath,
apiKey: process.env.LITE_LLM_API_KEY ?? null,
});
this.model = modelPreference ?? process.env.LITE_LLM_MODEL_PREF ?? null;
if (!this.model) throw new Error("LiteLLM must have a valid model set.");
this.limits = {
history: this.promptWindowLimit() * 0.15,
system: this.promptWindowLimit() * 0.15,
user: this.promptWindowLimit() * 0.7,
};
this.embedder = embedder ?? new NativeEmbedder();
this.defaultTemp = 0.7;
this.log(`Inference API: ${this.basePath} Model: ${this.model}`);
}
log(text, ...args) {
console.log(`\x1b[36m[${this.className}]\x1b[0m ${text}`, ...args);
}
#appendContext(contextTexts = []) {
if (!contextTexts || !contextTexts.length) return "";
return (View on GitHub (pinned to 526360e320)
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.
Example fix
// before: .env LITE_LLM_BASE_PATH='http://127.0.0.1:4000' // after LITE_LLM_BASE_PATH='http://127.0.0.1:4000' LITE_LLM_MODEL_PREF='gpt-3.5-turbo'
Defensive patterns
Strategy: validation
Validate before calling
function validateLiteLLMModel(modelPreference) {
const model = modelPreference ?? process.env.LITE_LLM_MODEL_PREF ?? null;
if (!model) {
throw new Error(
'No LiteLLM model set. Set LITE_LLM_MODEL_PREF in .env or select a model in workspace settings.'
);
}
return model;
}
const model = validateLiteLLMModel(workspaceModel); Type guard
/** @returns {model is string} */
function isValidModelName(model) {
return typeof model === 'string' && model.trim().length > 0;
} Try / catch
try {
const llm = new LiteLLM(embedder, model);
} catch (e) {
if (e.message.includes('valid model set')) {
console.error('Configure LITE_LLM_MODEL_PREF or select a model in workspace settings.');
return null;
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- KoboldCPP must have a valid model set.
- No Lemonade Model Pref was set.
- LiteLLM must have a valid base path to use for the api.
- LMStudio must have a valid model set.
- GenericOpenAI must have a valid model set.
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/7517ff8bb6234abf.
Report an issue: GitHub.