Mintplex-Labs/anything-llm · error · Error

e.message

Error message

e.message

What it means

Same info-loss re-wrap as the Minimax equivalent: .catch((e) => { throw new Error(e.message); }) discards the OpenAI client's structured error (status, type, retry-after) and rethrows a plain Error. Unlike Minimax, on a *successful* call with no choices Mistral returns null rather than throwing (see getChatCompletion body), so this catch is strictly for upstream transport/API errors.

Source

Thrown at server/utils/AiProviders/mistral/index.js:124

      },
    ];
  }

  async getChatCompletion(messages = null, { temperature = 0.7 }) {
    if (!(await this.isValidChatCompletionModel(this.model)))
      throw new Error(
        `Mistral chat: ${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.duration,
        duration: result.duration,
        model: this.model,

View on GitHub (pinned to 526360e320)

Solutions

  1. Read the message — upstream status/detail is embedded in the text.
  2. For auth-related text, verify/regenerate MISTRAL_API_KEY.
  3. For rate-limit text, add backoff/retry and reduce concurrency.
  4. For diagnosis, log the original error object before re-wrapping.

Example fix

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

// after
.catch((e) => {
  const err = new Error(`Mistral chat failed (${e?.status}): ${e.message}`);
  err.cause = e;
  err.status = e?.status;
  throw err;
})
Defensive patterns

Strategy: retry

Try / catch

try {
  await llm.getChatCompletion(messages, { temperature });
} catch (e) {
  const msg = e.message || '';
  if (/429|rate limit/i.test(msg))      { /* backoff + retry */ }
  else if (/401|unauthor|api key/i.test(msg)) { /* rotate key */ }
  else { /* surface */ }
}

Prevention

When it happens

Trigger: Any HTTP-level failure from the Mistral chat completion call: 401, 429, 400, network timeout, or 5xx — each flattened to its message string.

Common situations: Invalid/expired Mistral key; rate limiting on the Mistral plan; malformed messages payload; transient Mistral outage; inability to branch on status in the caller because only the string survives.

Related errors


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