{"record":{"id":"8e8822ec14c7245b","repo":"Mintplex-Labs/anything-llm","slug":"groqai-chatcompletion-this-model-is-not-valid","errorCode":null,"errorMessage":"GroqAI:chatCompletion: ${this.model} is not valid for chat completion!","messagePattern":"GroqAI:chatCompletion: (.+?) is not valid for chat completion!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/groq/index.js","lineNumber":171,"sourceCode":"    systemPrompt = \"\",\n    contextTexts = [],\n    chatHistory = [],\n    userPrompt = \"\",\n    attachments = [], // This is the specific attachment for only this prompt\n  }) {\n    // NOTICE: SEE GroqLLM.#conditionalPromptStruct for more information on how attachments are handled with Groq.\n    return this.#conditionalPromptStruct({\n      systemPrompt,\n      contextTexts,\n      chatHistory,\n      userPrompt,\n      attachments,\n    });\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    if (!(await this.isValidChatCompletionModel(this.model)))\n      throw new Error(\n        `GroqAI:chatCompletion: ${this.model} is not valid for chat completion!`\n      );\n\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.openai.chat.completions\n        .create({\n          model: this.model,\n          messages,\n          temperature,\n        })\n        .catch((e) => {\n          throw new Error(e.message);\n        })\n    );\n\n    if (\n      !result.output.hasOwnProperty(\"choices\") ||\n      result.output.choices.length === 0","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/utils/AiProviders/groq/index.js#L153-L189","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nconst llm = new GroqLLM(embedder, \"\"); // model falls back to env/default\n\n// after — pin an explicit, current model\nconst llm = new GroqLLM(embedder, \"llama-3.3-70b-versatile\");","handlingStrategy":"validation","validationCode":"const model = modelPreference || process.env.GROQ_MODEL_PREF || \"llama-3.1-8b-instant\";\nif (!model) throw new Error(\"No Groq model resolved\");\nif (!(await llm.isValidChatCompletionModel(model))) throw new Error(`Model ${model} rejected`);\nconst res = await llm.getChatCompletion(messages);","typeGuard":"/** True when the instance can safely serve non-stream completions. */\nfunction isRunnableGroqInstance(llm) {\n  return llm instanceof GroqLLM && typeof llm.model === \"string\" && llm.model.length > 0;\n}","tryCatchPattern":"try {\n  await llm.getChatCompletion(messages);\n} catch (e) {\n  if (/not valid for chat completion/i.test(e.message)) {\n    // model state lost — rebuild instance with an explicit model\n  } else throw e;\n}","preventionTips":["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."],"tags":["groq","anythingllm","model-selection","validation","chat-completion"],"backgroundTag":"model-not-found","analyzedSha":"f92433b4ea0598492a1e6645ea22addbb4dd1287","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}