Mintplex-Labs/anything-llm · error · Error
GroqAI:chatCompletion
Error message
GroqAI:chatCompletion: ${this.model} is not valid for chat completion! What it means
Guard at the top of GroqLLM.getChatCompletion(): it awaits isValidChatCompletionModel(this.model) and throws if that returns false. In this codebase isValidChatCompletionModel is simply `return !!modelName` (server/utils/AiProviders/groq/index.js:60), so it validates only that a model name exists — it does NOT check the model against Groq's live model list. Because the constructor falls back `modelPreference || GROQ_MODEL_PREF || "llama-3.1-8b-instant"`, this.model is almost never falsy, making this a defensive near-unreachable check.
Solutions
- Inspect what this.model actually resolved to (constructor default is llama-3.1-8b-instant) — if you truly got this throw, it is empty, so set GROQ_MODEL_PREF or pass a modelPreference when constructing.
- Set GROQ_MODEL_PREF in the backend .env to a currently listed Groq model id (check console.groq.com/models).
- If the intent was 'model rejected by Groq', note this guard cannot produce that; the actual API rejection is rethrown from the .catch inside getChatCompletion with the SDK's message — debug that instead.
- Upgrade AnythingLLM: newer Groq models rotate frequently; decommissioned ids fail at request time, so pin a supported id.
Example fix
// before const llm = new GroqLLM(embedder, ""); // model falls back to env/default // after — pin an explicit, current model const llm = new GroqLLM(embedder, "llama-3.3-70b-versatile");
Defensive patterns
Strategy: validation
Validate before calling
const model = modelPreference || process.env.GROQ_MODEL_PREF || "llama-3.1-8b-instant";
if (!model) throw new Error("No Groq model resolved");
if (!(await llm.isValidChatCompletionModel(model))) throw new Error(`Model ${model} rejected`);
const res = await llm.getChatCompletion(messages); Type guard
/** True when the instance can safely serve non-stream completions. */
function isRunnableGroqInstance(llm) {
return llm instanceof GroqLLM && typeof llm.model === "string" && llm.model.length > 0;
} Try / catch
try {
await llm.getChatCompletion(messages);
} catch (e) {
if (/not valid for chat completion/i.test(e.message)) {
// model state lost — rebuild instance with an explicit model
} else throw e;
} Prevention
- Always pass a non-empty modelPreference or set GROQ_MODEL_PREF so the constructor default chain is never relied on.
- Treat this message as a state-corruption signal: log llm.model whenever it fires.
- Pin model ids you have verified against console.groq.com/models; Groq decommissions ids frequently.
When it happens
Trigger: Calling llm.getChatCompletion(messages) on a GroqLLM instance whose this.model is an empty string or null at call time. Practically reachable only if the instance was constructed with an explicitly falsy-but-present model and the env default chain was bypassed (e.g., a mutated instance or a monkey-patched constructor default).
Common situations: Almost never seen in production because the constructor's || chain guarantees a default model name. Developers encounter the string in logs usually as a red herring when the real failure is the Groq API rejecting the model id server-side (404 model_decommissioned), which surfaces later, not from this guard.
Related errors
- GroqAI:streamChatCompletion
- LMStudio chat: is not valid or defined model for chat…
- NVIDIA NIM chat: is not valid or defined model for chat…
- ApiPie chat: is not valid for chat completion!
- data.message || "Could not update slash command preset."
AI-assisted analysis of Mintplex-Labs/anything-llm@f92433b4ea (2026-08-18).
Data as JSON: /api/errors/8e8822ec14c7245b.
Report an issue: GitHub.
Appendix: source
Thrown at server/utils/AiProviders/groq/index.js:171
systemPrompt = "",
contextTexts = [],
chatHistory = [],
userPrompt = "",
attachments = [], // This is the specific attachment for only this prompt
}) {
// NOTICE: SEE GroqLLM.#conditionalPromptStruct for more information on how attachments are handled with Groq.
return this.#conditionalPromptStruct({
systemPrompt,
contextTexts,
chatHistory,
userPrompt,
attachments,
});
}
async getChatCompletion(messages = null, { temperature = 0.7 }) {
if (!(await this.isValidChatCompletionModel(this.model)))
throw new Error(
`GroqAI:chatCompletion: ${this.model} is not valid for chat completion!`
);
const result = await LLMPerformanceMonitor.measureAsyncFunction(
this.openai.chat.completions
.create({
model: this.model,
messages,
temperature,
})
.catch((e) => {
throw new Error(e.message);
})
);
if (
!result.output.hasOwnProperty("choices") ||
result.output.choices.length === 0View on GitHub (pinned to f92433b4ea)