{"record":{"id":"a99b787b3bfd7c8a","repo":"Mintplex-Labs/anything-llm","slug":"groqai-streamchatcompletion-this-model-is-not","errorCode":null,"errorMessage":"GroqAI:streamChatCompletion: ${this.model} is not valid for chat completion!","messagePattern":"GroqAI:streamChatCompletion: (.+?) is not valid for chat completion!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/groq/index.js","lineNumber":212,"sourceCode":"      textResponse: result.output.choices[0].message.content,\n      metrics: {\n        prompt_tokens: result.output.usage.prompt_tokens || 0,\n        completion_tokens: result.output.usage.completion_tokens || 0,\n        total_tokens: result.output.usage.total_tokens || 0,\n        outputTps:\n          result.output.usage.completion_tokens /\n          result.output.usage.completion_time,\n        duration: result.output.usage.total_time,\n        model: this.model,\n        provider: this.className,\n        timestamp: new Date(),\n      },\n    };\n  }\n\n  async streamGetChatCompletion(messages = null, { temperature = 0.7 }) {\n    if (!(await this.isValidChatCompletionModel(this.model)))\n      throw new Error(\n        `GroqAI:streamChatCompletion: ${this.model} is not valid for chat completion!`\n      );\n\n    const measuredStreamRequest = await LLMPerformanceMonitor.measureStream({\n      func: this.openai.chat.completions.create({\n        model: this.model,\n        stream: true,\n        messages,\n        temperature,\n      }),\n      messages,\n      runPromptTokenCalculation: false,\n      modelTag: this.model,\n      provider: this.className,\n    });\n\n    return measuredStreamRequest;\n  }","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/utils/AiProviders/groq/index.js#L194-L230","documentation":"Same falsy-model guard as the non-stream path, but at the top of GroqLLM.streamGetChatCompletion(). isValidChatCompletionModel only checks the name is non-empty (`!!modelName`), so this fires only when this.model is empty/null right before streaming. The constructor's fallback chain (modelPreference || GROQ_MODEL_PREF || \"llama-3.1-8b-instant\") makes that a defensive, near-unreachable branch.","triggerScenarios":"Invoking llm.streamGetChatCompletion(messages) (i.e., streaming a chat response with Groq selected) on an instance whose model resolved to an empty string — only realistic with a mutated instance or a patched constructor default that bypasses the fallback.","commonSituations":"Effectively never hit in normal AnythingLLM use; appears in stack traces only as a misdiagnosis when the actual streaming failure is an HTTP-level error from the Groq API (bad key, decommissioned model, rate limit) thrown later inside LLMPerformanceMonitor.measureStream.","solutions":["Log the instance's resolved model (llm.model) before streaming; if empty, set GROQ_MODEL_PREF or pass modelPreference at construction.","Pin GROQ_MODEL_PREF to a live model id from console.groq.com/models so the default chain never resolves empty.","If streaming actually fails mid-request, debug the underlying SDK error from measureStream instead of this guard."],"exampleFix":"// before\nGROQ_MODEL_PREF=            # blank in .env\n\n// after\nGROQ_MODEL_PREF=llama-3.3-70b-versatile","handlingStrategy":"validation","validationCode":"if (!llm.model) throw new Error(\"GroqLLM has no model — reconstruct with modelPreference or set GROQ_MODEL_PREF\");\nawait llm.streamGetChatCompletion(messages);","typeGuard":"function isStreamableGroqInstance(llm) {\n  return llm instanceof GroqLLM && typeof llm.model === \"string\" && llm.model.length > 0;\n}","tryCatchPattern":"try {\n  await llm.streamGetChatCompletion(messages);\n} catch (e) {\n  if (/not valid for chat completion/i.test(e.message)) rebuildProviderWithModel();\n  else throw e;\n}","preventionTips":["Never mutate llm.model after construction; create a fresh instance per model switch.","Set GROQ_MODEL_PREF explicitly in env so defaults never silently mask a missing workspace setting.","When streaming fails, inspect the measureStream/SDK error for the real cause before suspecting this guard."],"tags":["groq","anythingllm","streaming","model-selection","validation"],"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"}