Mintplex-Labs/anything-llm · error · Error
Foundry chat: ${this.model} is not valid or defined model fo
Error message
Foundry chat: ${this.model} is not valid or defined model for chat completion! What it means
Thrown at the top of getChatCompletion when this.model is falsy. The constructor sets this.model from modelPreference || process.env.FOUNDRY_MODEL_PREF; if both are unset/empty the field stays undefined/null/'' and the method bails before doing any work. It is a guard against sending an empty `model` field to the Foundry OpenAI endpoint.
Source
Thrown at server/utils/AiProviders/foundry/index.js:307
attachments = [],
}) {
const prompt = {
role: "system",
content: `${systemPrompt}${this.#appendContext(contextTexts)}`,
};
return [
prompt,
...formatChatHistory(chatHistory, this.#generateContent),
{
role: "user",
content: this.#generateContent({ userPrompt, attachments }),
},
];
}
async getChatCompletion(messages = null, { temperature = 0.7 }) {
if (!this.model)
throw new Error(
`Foundry chat: ${this.model} is not valid or defined model for chat completion!`
);
// max_completion_tokens is required by Foundry (it caps output at 1024
// otherwise), so the window has to be resolved before the request is built.
await this.assertModelContextLimits();
await this.assertModelLoaded();
const result = await LLMPerformanceMonitor.measureAsyncFunction(
this.openai.chat.completions
.create({
model: this.model,
messages,
temperature,
max_completion_tokens: this.promptWindowLimit(),
})
.catch((e) => {
throw new Error(e.message);
})View on GitHub (pinned to 526360e320)
Solutions
- Set FOUNDRY_MODEL_PREF in .env to a valid Foundry model id
- Pass an explicit modelPreference when constructing FoundryLLM from code
- Re-select the model in the AnythingLLM provider settings so it is persisted
- Restart the server after updating .env so process.env reflects the change
Example fix
// before const llm = new FoundryLLM(embedder); // no modelPreference, FOUNDRY_MODEL_PREF unset // after // .env: FOUNDRY_MODEL_PREF=Phi-3-mini-4k-instruct-cuda const llm = new FoundryLLM(embedder);
Defensive patterns
Strategy: validation
Validate before calling
function hasFoundryModel() {
return Boolean(process.env.FOUNDRY_MODEL_PREF);
}
// guard before constructing or before sending
if (!hasFoundryModel()) {
throw new ConfigError('Set FOUNDRY_MODEL_PREF to a valid Foundry model id.');
} Prevention
- Require a model id in the provider-settings UI before saving
- Default FOUNDRY_MODEL_PREF in your .env template so it is never blank
- Validate model config at startup, not at first inference
When it happens
Trigger: Invoking getChatCompletion on a FoundryLLM instance where neither a modelPreference argument nor FOUNDRY_MODEL_PREF was supplied at construction time.
Common situations: FOUNDRY_MODEL_PREF left blank in .env and the caller passed no modelPreference; the workspace/provider configuration was migrated and the model pref got wiped; selecting Foundry without picking a default model in the UI.
Related errors
- No Foundry Base Path was set.
- Could not load ${this.model} into Foundry Local: ${error}
- e.message
- GenericOpenAI must have a valid model set.
- KoboldCPP must have a valid model set.
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/a0c363a51f6769e1.
Report an issue: GitHub.