Mintplex-Labs/anything-llm · error · Error

e.message

Error message

e.message

What it means

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.

Solutions

  1. 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.
  2. For 429s, retry with exponential backoff honoring retry-after, and lower parallelism of AnythingLLM embed/chat requests.
  3. 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.
  4. For network errors, verify egress/proxy settings from the server host (curl https://api.groq.com/openai/v1/models).
  5. Check result.output.choices emptiness separately: this throw is transport/auth-level; a 200 with zero choices instead returns null.

Example fix

// before
const response = await groqLlm.getChatCompletion(messages);

// after — surface the underlying cause and retry transient 429s
async function safeCompletion(llm, messages, retries = 3) {
  for (let attempt = 0; attempt <= retries; attempt++) {
    try {
      return await llm.getChatCompletion(messages);
    } catch (err) {
      if (/rate limit/i.test(err.message) && attempt < retries) {
        await new Promise((r) => setTimeout(r, 2 ** attempt * 1000));
        continue;
      }
      throw err; // 401/404 are not transient — rethrow with message intact
    }
  }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight the key and model before chatting (cheap GETs, no tokens burned)
async function groqPreFlight() {
  const res = await fetch("https://api.groq.com/openai/v1/models", {
    headers: { Authorization: `Bearer ${process.env.GROQ_API_KEY}` },
  });
  if (res.status === 401) throw new Error("GROQ_API_KEY invalid");
  const { data } = await res.json();
  if (!data.some((m) => m.id === process.env.GROQ_MODEL_PREF)) throw new Error("Model id not in Groq catalog");
}

Type guard

/** Narrow transient (retryable) Groq failures from permanent ones. */
function isTransientGroqError(e) {
  return /rate limit|timeout|temporarily|overloaded/i.test(e?.message ?? "");
}

Try / catch

for (let attempt = 0; attempt <= 3; attempt++) {
  try {
    return await llm.getChatCompletion(messages);
  } catch (e) {
    if (isTransientGroqError(e) && attempt < 3) {
      await new Promise((r) => setTimeout(r, 2 ** attempt * 500));
      continue;
    }
    throw e; // 401/404/model_decommissioned — fix config, do not retry
  }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@f92433b4ea (2026-08-18). Data as JSON: /api/errors/3cc3a90cfea9fad8. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/AiProviders/groq/index.js:183

      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 === 0
    )
      return null;

    return {
      textResponse: result.output.choices[0].message.content,
      metrics: {
        prompt_tokens: result.output.usage.prompt_tokens || 0,
        completion_tokens: result.output.usage.completion_tokens || 0,
        total_tokens: result.output.usage.total_tokens || 0,
        outputTps:
          result.output.usage.completion_tokens /
          result.output.usage.completion_time,

View on GitHub (pinned to f92433b4ea)