Mintplex-Labs/anything-llm · error · Error
LocalAi chat: ${this.model} is not valid for chat completion
Error message
LocalAi chat: ${this.model} is not valid for chat completion! What it means
Thrown by LocalAiLLM.streamGetChatCompletion when `isValidChatCompletionModel(this.model)` returns false. Like error 238, this is dead code because isValidChatCompletionModel unconditionally returns true. Note the casing inconsistency: the message says 'LocalAi chat' (mixed case) while the getChatCompletion variant (error 238) says 'LocalAI chat' (all caps) — a minor string mismatch that makes log-grepping inconsistent.
Source
Thrown at server/utils/AiProviders/localAi/index.js:158
return {
textResponse: result.output.choices[0].message.content,
metrics: {
prompt_tokens: promptTokens,
completion_tokens: completionTokens,
total_tokens: promptTokens + completionTokens,
outputTps: completionTokens / result.duration,
duration: result.duration,
model: this.model,
provider: this.className,
timestamp: new Date(),
},
};
}
async streamGetChatCompletion(messages = null, { temperature = 0.7 }) {
if (!(await this.isValidChatCompletionModel(this.model)))
throw new Error(
`LocalAi chat: ${this.model} is not valid for chat completion!`
);
const measuredStreamRequest = await LLMPerformanceMonitor.measureStream({
func: this.openai.chat.completions.create({
model: this.model,
stream: true,
messages,
temperature,
}),
messages,
runPromptTokenCalculation: true,
modelTag: this.model,
provider: this.className,
});
return measuredStreamRequest;
}
View on GitHub (pinned to 526360e320)
Solutions
- This error should not occur — if encountered, investigate custom subclasses or monkey-patching of isValidChatCompletionModel.
- Fix the message casing inconsistency: change 'LocalAi chat' to 'LocalAI chat' for consistency with the getChatCompletion variant (error 238).
- If adding real model validation, override isValidChatCompletionModel to query the LocalAI server's model list.
Example fix
// before — inconsistent casing between getChatCompletion and streamGetChatCompletion
throw new Error(
`LocalAi chat: ${this.model} is not valid for chat completion!`
);
// after — consistent casing
throw new Error(
`LocalAI chat: ${this.model} is not valid for chat completion!`
); Defensive patterns
Strategy: validation
Validate before calling
// This error is currently unreachable because isValidChatCompletionModel always returns true.
// If you add real validation, check the model before calling streamGetChatCompletion:
async function validateLocalAIModel(provider) {
const res = await fetch(`${process.env.LOCAL_AI_BASE_PATH}/models`);
const data = await res.json();
const available = (data.data || []).map((m) => m.id);
if (!available.includes(provider.model)) {
throw new Error(`Model "${provider.model}" not available on LocalAI server.`);
}
return true;
} Try / catch
// Currently unnecessary since the guard is dead code, but for future-proofing:
try {
const stream = await localaiProvider.streamGetChatCompletion(messages, { temperature: 0.7 });
} catch (e) {
// Note: message says 'LocalAi' (mixed case), not 'LocalAI'
if (e.message.includes('not valid for chat completion')) {
console.error('LocalAI model validation failed for:', localaiProvider.model);
} else {
throw e;
}
} Prevention
- This error is dead code in current implementation — no prevention needed.
- If adding real model validation, override isValidChatCompletionModel to check the server's model list.
- Fix the message casing inconsistency ('LocalAi' vs 'LocalAI') so log-based error searching works reliably.
When it happens
Trigger: Unreachable in normal operation. The guard `if (!(await this.isValidChatCompletionModel(this.model)))` always evaluates to false because the method returns true. Would only fire if the class or a subclass overrode isValidChatCompletionModel with validation that rejects the model.
Common situations: Practically never seen. The streaming path is the primary chat code path in AnythingLLM. If a future change adds real model validation, this guard would become active. The casing inconsistency in the message is a latent bug for log-based error searching.
Related errors
- LocalAI chat: ${this.model} is not valid for chat completion
- GroqAI:streamChatCompletion: ${this.model} is not valid for
- LMStudio chat: ${this.model} is not valid or defined model f
- Minimax stream: ${this.model} is not valid for chat completi
- Stream returned undefined chunk. Aborting reply - check mode
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/14ab41d2c114019a.
Report an issue: GitHub.