Mintplex-Labs/anything-llm · error · Error

e.message

Error message

e.message

What it means

Re-throws the OpenAI SDK error when the DeepSeek chat completions request (POST /v1/chat/completions) fails. The .catch converts the structured SDK error into a bare Error carrying only e.message, discarding the HTTP status, error code, and response body. DeepSeek SDK errors typically carry meaningful messages (e.g. 'Frequent Request', 'Insufficient Balance').

Source

Thrown at server/utils/AiProviders/deepseek/index.js:111

      textResponse = `<think>${message.reasoning_content}</think>${textResponse}`;
    return textResponse;
  }

  async getChatCompletion(messages = null, { temperature = 0.7 }) {
    if (!(await this.isValidChatCompletionModel(this.model)))
      throw new Error(
        `DeepSeek 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
    )
      throw new Error(
        `Invalid response body returned from DeepSeek: ${JSON.stringify(result.output)}`
      );

    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.duration,

View on GitHub (pinned to 526360e320)

Solutions

  1. Read e.message — DeepSeek surfaces 'Insufficient Balance' or 'Frequent Request' which directly indicates the action needed.
  2. Top up the DeepSeek account balance if the message references insufficient funds.
  3. For 'Frequent Request', reduce request rate or add a delay/retry with backoff.
  4. Patch the catch to preserve the original error for better diagnostics.

Example fix

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

// after
.catch((e) => {
  throw e; // keep status/code for upstream handling
Defensive patterns

Strategy: retry

Type guard

function isDeepSeekSdkError(e) {
  return e instanceof Error && typeof e.status === 'number';
}

Try / catch

try {
  return await deepseek.getChatCompletion(messages, { temperature });
} catch (e) {
  if (/insufficient balance/i.test(e.message))
    throw new Error('DeepSeek account balance exhausted — top up at platform.deepseek.com');
  if (/frequent request|429/i.test(e.message)) {
    await sleep(2000 * attempt);
    return retry();
  }
  throw e;
}

Prevention

When it happens

Trigger: DeepSeek account balance exhausted (error message references insufficient balance); rate limiting ('Frequent Request'); invalid or oversized message payload; model temporarily unavailable; network timeout to api.deepseek.com.

Common situations: Free-tier DeepSeek key hitting rate limits during batch processing; prepaid balance running out mid-session; sending a context window that exceeds the model's limit producing a 400; transient DeepSeek API instability.

Related errors


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