Mintplex-Labs/anything-llm · error · Error

${e.message}

Error message

${e.message}

What it means

Re-throws the raw `e.message` from the OpenAI SDK's `chat.completions.create` rejection inside CerebrasLLM.getChatCompletion. The SDK call goes to https://api.cerebras.ai/v1/chat/completions; on rejection the .catch console.errors and throws a fresh Error with just the message. parseReasoningFromResponse is never reached.

Source

Thrown at server/utils/AiProviders/cerebras/index.js:210

   */
  #parseReasoningFromResponse({ message }) {
    let textResponse = message?.content ?? "";
    if (!!message?.reasoning && message.reasoning.trim().length > 0)
      textResponse = `<think>${message.reasoning}</think>${textResponse}`;
    return textResponse;
  }

  async getChatCompletion(messages = null, { temperature = 0.7 }) {
    const result = await LLMPerformanceMonitor.measureAsyncFunction(
      this.openai.chat.completions
        .create({
          model: this.model,
          messages,
          temperature,
        })
        .catch((e) => {
          console.error(e);
          throw new Error(e.message);
        })
    );

    if (
      !result.output.hasOwnProperty("choices") ||
      result.output.choices.length === 0
    )
      return null;

    return {
      textResponse: this.#parseReasoningFromResponse(result.output.choices[0]),
      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.time_info.completion_time,

View on GitHub (pinned to 526360e320)

Solutions

  1. Inspect e.message (console.error'd) for the Cerebras status text and fix the named cause.
  2. On 401, update CEREBRAS_API_KEY in .env and restart.
  3. On 429, reduce concurrency / add backoff; on 400 verify the model supports the params.
  4. On transport errors, retry once with backoff, then surface to the user.

Example fix

// before
.catch((e) => {
  console.error(e);
  throw new Error(e.message);
})

// after - preserve status/retryability
.catch((e) => {
  console.error(e);
  const err = new Error(e.message);
  err.status = e.status ?? e.response?.status;
  throw err;
})
Defensive patterns

Strategy: try-catch

Validate before calling

// Cheap pre-flight checks
if (!this.model) throw new Error("No Cerebras model selected.");
if (!Array.isArray(messages) || messages.length === 0)
  throw new Error("Messages must be a non-empty array.");

Type guard

/** @param {unknown} e @returns {boolean} */
function isOpenAiCompatError(e) {
  return e != null && typeof e === "object" &&
    typeof e.message === "string" &&
    (typeof e.status === "number" || typeof e.response?.status === "number");
}

Try / catch

try {
  const res = await llm.getChatCompletion(messages, { temperature });
} catch (e) {
  const status = e.status ?? e.response?.status;
  if (status === 401) await refreshCerebrasKey();
  else if (status === 429) await backoffRetry(fn);
  else if (status >= 500) await backoffRetry(fn);
  else throw e;
}

Prevention

When it happens

Trigger: Calling getChatCompletion and the Cerebras API rejects: 401 invalid key, 429 rate limit, 400 unsupported model or bad temperature, 404 unknown model id, or a transport-level error (timeout/reset).

Common situations: Key expired or rotated; selected a model not enabled for the account; rate-limited; passed an unsupported parameter; network blip; Cerebras API briefly unavailable.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/83cd3cb2c036bc25. Report an issue: GitHub.