{"record":{"id":"6f48b702427c53b3","repo":"Mintplex-Labs/anything-llm","slug":"e-message-6f48b7","errorCode":null,"errorMessage":"e.message","messagePattern":"e\\.message","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/deepseek/index.js","lineNumber":111,"sourceCode":"      textResponse = `<think>${message.reasoning_content}</think>${textResponse}`;\n    return textResponse;\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    if (!(await this.isValidChatCompletionModel(this.model)))\n      throw new Error(\n        `DeepSeek chat: ${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      throw new Error(\n        `Invalid response body returned from DeepSeek: ${JSON.stringify(result.output)}`\n      );\n\n    return {\n      textResponse: this.#parseReasoningFromResponse(result.output.choices[0]),\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: result.output.usage.completion_tokens / result.duration,","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/deepseek/index.js#L93-L129","documentation":"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').","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read e.message — DeepSeek surfaces 'Insufficient Balance' or 'Frequent Request' which directly indicates the action needed.","Top up the DeepSeek account balance if the message references insufficient funds.","For 'Frequent Request', reduce request rate or add a delay/retry with backoff.","Patch the catch to preserve the original error for better diagnostics."],"exampleFix":"// before\n.catch((e) => {\n  throw new Error(e.message);\n})\n\n// after\n.catch((e) => {\n  throw e; // keep status/code for upstream handling","handlingStrategy":"retry","validationCode":null,"typeGuard":"function isDeepSeekSdkError(e) {\n  return e instanceof Error && typeof e.status === 'number';\n}","tryCatchPattern":"try {\n  return await deepseek.getChatCompletion(messages, { temperature });\n} catch (e) {\n  if (/insufficient balance/i.test(e.message))\n    throw new Error('DeepSeek account balance exhausted — top up at platform.deepseek.com');\n  if (/frequent request|429/i.test(e.message)) {\n    await sleep(2000 * attempt);\n    return retry();\n  }\n  throw e;\n}","preventionTips":["Monitor the DeepSeek prepaid balance and set low-balance alerts.","Add rate-limit spacing for free-tier keys.","Preserve the original SDK error (not just e.message) to retain the HTTP status for branching."],"tags":["deepseek","openai-sdk","chat-completion","api-error","error-rewrap"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}