{"record":{"id":"6cc892cc122e0ac5","repo":"Mintplex-Labs/anything-llm","slug":"e-message-6cc892","errorCode":null,"errorMessage":"e.message","messagePattern":"e\\.message","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/minimax/index.js","lineNumber":96,"sourceCode":"    };\n    return [prompt, ...chatHistory, { role: \"user\", content: userPrompt }];\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    if (!(await this.isValidChatCompletionModel(this.model)))\n      throw new Error(\n        `Minimax 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 Minimax: ${JSON.stringify(result.output)}`\n      );\n\n    return {\n      textResponse: result.output.choices[0].message.content,\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":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/minimax/index.js#L78-L114","documentation":"The .catch((e) => { throw new Error(e.message); }) wraps ANY failure from openai.chat.completions.create (auth, rate limit, 4xx/5xx, network) into a plain Error carrying only the string message. This loses the original error class, status code, headers, and retry-after info — an info-loss anti-pattern. The literal 'e.message' is the source token; at runtime the message is the upstream error's text.","triggerScenarios":"Any upstream failure during the Minimax chat completion HTTP call: 401 (bad key), 429 (rate/quota limit), 400 (malformed messages), network/timeout, or 5xx from Minimax. Each surfaces here as a generic Error with only the message string.","commonSituations":"Expired or revoked API key surfacing as an auth error string; hitting Minimax rate/quota limits; a malformed message array; transient upstream outage; the re-wrap making it impossible to distinguish 429 from 5xx in a catch block.","solutions":["Inspect the full message text — it usually contains the upstream status/detail.","If the message indicates 401/auth, rotate/verify MINIMAX_API_KEY.","If it indicates 429 or timeout, reduce request rate and retry with backoff.","For diagnosis, temporarily log e (not just e.message) upstream, or patch the catch to rethrow the original error."],"exampleFix":"// before\n.catch((e) => {\n  throw new Error(e.message);  // loses status/type\n})\n\n// after\n.catch((e) => {\n  const status = e?.status ?? e?.response?.status;\n  const err = new Error(`Minimax chat failed (${status}): ${e.message}`);\n  err.cause = e;\n  err.status = status;\n  throw err;\n})","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// The message string is all you get; branch on known substrings\ntry {\n  await llm.getChatCompletion(messages, { temperature });\n} catch (e) {\n  const msg = e.message || '';\n  if (/429|rate limit/i.test(msg))      { /* backoff and retry */ }\n  else if (/401|unauthor|invalid api key/i.test(msg)) { /* rotate key */ }\n  else if (/timeout|etimedout/i.test(msg)) { /* retry once */ }\n  else { /* surface as hard error */ }\n}","preventionTips":["Prefer patching the catch to rethrow e (or attach e.cause/e.status) so callers can branch on type.","Log the original error object during incident diagnosis, not just e.message.","Add a retry-with-backoff layer for 429/5xx upstream errors."],"tags":["minimax","error-handling","openai-client","anti-pattern","rate-limit"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}