Mintplex-Labs/anything-llm · error · Error
GenericOpenAI must have a valid model set.
Error message
GenericOpenAI must have a valid model set.
What it means
Thrown after the constructor resolves this.model from modelPreference ?? process.env.GENERIC_OPEN_AI_MODEL_PREF ?? null. If all three are nullish, this.model is null and the constructor aborts. Unlike the base path, a default cannot be invented because Generic OpenAI has no idea what models the arbitrary endpoint serves.
Source
Thrown at server/utils/AiProviders/genericOpenAi/index.js:41
);
this.className = "GenericOpenAiLLM";
this.basePath = process.env.GENERIC_OPEN_AI_BASE_PATH;
this.openai = new OpenAIApi({
baseURL: this.basePath,
apiKey: process.env.GENERIC_OPEN_AI_API_KEY ?? null,
defaultHeaders: {
"User-Agent": getAnythingLLMUserAgent(),
...GenericOpenAiLLM.parseCustomHeaders(),
},
});
this.model =
modelPreference ?? process.env.GENERIC_OPEN_AI_MODEL_PREF ?? null;
this.maxTokens = process.env.GENERIC_OPEN_AI_MAX_TOKENS
? toValidNumber(process.env.GENERIC_OPEN_AI_MAX_TOKENS, 1024)
: 1024;
if (!this.model)
throw new Error("GenericOpenAI 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);
}
/**
* Parses custom headers from a CSV-formatted environment variable.
* Format: "Header-Name:value,Another-Header:value2"View on GitHub (pinned to 526360e320)
Solutions
- Query the endpoint's model list (curl $BASE_PATH/models) and set GENERIC_OPEN_AI_MODEL_PREF to a returned id
- Pass modelPreference explicitly when constructing from code
- Fill the model field in the Generic OpenAI provider UI
- Restart the server after updating .env
Example fix
// before // .env: GENERIC_OPEN_AI_BASE_PATH=http://localhost:1234/v1 // no model // after // .env: // GENERIC_OPEN_AI_BASE_PATH=http://localhost:1234/v1 // GENERIC_OPEN_AI_MODEL_PREF=llama-3.1-8b-instruct
Defensive patterns
Strategy: validation
Validate before calling
const model = modelPreference ?? process.env.GENERIC_OPEN_AI_MODEL_PREF;
if (!model) {
throw new ConfigError('GenericOpenAI needs GENERIC_OPEN_AI_MODEL_PREF.');
}
// optionally cross-check against GET $BASE_PATH/models Prevention
- Fetch the endpoint's /models list and let the user pick from it in the UI
- Persist the chosen model id alongside the base path so neither is forgotten
- Validate model presence before construction
When it happens
Trigger: Constructing GenericOpenAiLLM with no modelPreference while GENERIC_OPEN_AI_MODEL_PREF is also unset. The provider must be told which model id the target endpoint expects.
Common situations: User set the base path but forgot the model id; the endpoint serves models under different names than expected; copying a config template that omitted the model pref line.
Related errors
- GenericOpenAI must have a valid base path to use for the api
- KoboldCPP must have a valid model set.
- No Lemonade Model Pref was set.
- LiteLLM must have a valid model set.
- LMStudio must have a valid model set.
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/8ab6312ac794389b.
Report an issue: GitHub.