{"record":{"id":"3cc3a90cfea9fad8","repo":"Mintplex-Labs/anything-llm","slug":"e-message-3cc3a9","errorCode":null,"errorMessage":"e.message","messagePattern":"e\\.message","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/groq/index.js","lineNumber":183,"sourceCode":"      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\n    )\n      return null;\n\n    return {\n      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,","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/utils/AiProviders/groq/index.js#L165-L201","documentation":"This is the catch-all rethrow inside GroqLLM.getChatCompletion(): the OpenAI-compatible SDK call to POST https://api.groq.com/openai/v1/chat/completions failed, and the code re-wraps it as `throw new Error(e.message)`. The visible message is therefore the verbatim SDK/HTTP error text, not anything Groq-specific from this library. Typical payloads are 401 invalid api key, 404 model_decommissioned / model not found, 429 rate-limit headers, or network/ECONNREFUSED errors.","triggerScenarios":"Any failed chat completion HTTP request to Groq while this provider is the active LLM: expired or mistyped GROQ_API_KEY (401), a model id Groq has decommissioned (404 with model_decommissioned code), free-tier rate limits or org suspension (429), oversized prompt exceeding the model's context window, or the server having no egress to api.groq.com (timeout / getaddrinfo ENOTFOUND).","commonSituations":"Groq deprecating llama-3.1-70b/llava ids while GROQ_MODEL_PREF still pins them; hitting requests-per-minute caps during bulk document embedding/chat; key revoked after being committed to a public repo; corporate proxy blocking api.groq.com; sending attachments to a non-vision model.","solutions":["Read the propagated message literally — it names the real cause: 'Invalid API Key' → fix GROQ_API_KEY; 'model_decommissioned' or 404 → switch GROQ_MODEL_PREF to a current model; 'Rate limit reached' → back off or reduce concurrency.","For 429s, retry with exponential backoff honoring retry-after, and lower parallelism of AnythingLLM embed/chat requests.","For 404 model errors, list live models via curl https://api.groq.com/openai/v1/models -H \"Authorization: Bearer $GROQ_API_KEY\" and pin a supported id.","For network errors, verify egress/proxy settings from the server host (curl https://api.groq.com/openai/v1/models).","Check result.output.choices emptiness separately: this throw is transport/auth-level; a 200 with zero choices instead returns null."],"exampleFix":"// before\nconst response = await groqLlm.getChatCompletion(messages);\n\n// after — surface the underlying cause and retry transient 429s\nasync function safeCompletion(llm, messages, retries = 3) {\n  for (let attempt = 0; attempt <= retries; attempt++) {\n    try {\n      return await llm.getChatCompletion(messages);\n    } catch (err) {\n      if (/rate limit/i.test(err.message) && attempt < retries) {\n        await new Promise((r) => setTimeout(r, 2 ** attempt * 1000));\n        continue;\n      }\n      throw err; // 401/404 are not transient — rethrow with message intact\n    }\n  }\n}","handlingStrategy":"try-catch","validationCode":"// Pre-flight the key and model before chatting (cheap GETs, no tokens burned)\nasync function groqPreFlight() {\n  const res = await fetch(\"https://api.groq.com/openai/v1/models\", {\n    headers: { Authorization: `Bearer ${process.env.GROQ_API_KEY}` },\n  });\n  if (res.status === 401) throw new Error(\"GROQ_API_KEY invalid\");\n  const { data } = await res.json();\n  if (!data.some((m) => m.id === process.env.GROQ_MODEL_PREF)) throw new Error(\"Model id not in Groq catalog\");\n}","typeGuard":"/** Narrow transient (retryable) Groq failures from permanent ones. */\nfunction isTransientGroqError(e) {\n  return /rate limit|timeout|temporarily|overloaded/i.test(e?.message ?? \"\");\n}","tryCatchPattern":"for (let attempt = 0; attempt <= 3; attempt++) {\n  try {\n    return await llm.getChatCompletion(messages);\n  } catch (e) {\n    if (isTransientGroqError(e) && attempt < 3) {\n      await new Promise((r) => setTimeout(r, 2 ** attempt * 500));\n      continue;\n    }\n    throw e; // 401/404/model_decommissioned — fix config, do not retry\n  }\n}","preventionTips":["Rate-limit your own request fan-out to Groq; 429s dominate bursty workloads.","Wrap the call and preserve e.message verbatim — it carries the only actionable detail (this library re-wraps it).","Monitor for 'model_decommissioned' and treat it as a config alarm, not a runtime bug.","Keep prompts within the model's context window; oversized payloads throw here too."],"tags":["groq","openai-compatible","http-error","rate-limit","auth","anythingllm"],"backgroundTag":"api-request-failed","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"}