{"record":{"id":"981cbaab5da4258f","repo":"Mintplex-Labs/anything-llm","slug":"e-message-981cba","errorCode":null,"errorMessage":"${e.message}","messagePattern":"\\$\\{e\\.message\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/cometapi/index.js","lineNumber":210,"sourceCode":"      },\n    ];\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    if (!(await this.isValidChatCompletionModel(this.model)))\n      throw new Error(\n        `CometAPI 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      return null;\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,\n        duration: result.duration,\n        model: this.model,","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/cometapi/index.js#L192-L228","documentation":"Re-throws the OpenAI SDK error message when the CometAPI OpenAI-compatible chat completions request fails. The .catch wraps the SDK error into a generic Error, stripping the original error object's status code, type, and response metadata. Any transport-layer or API-layer failure from the OpenAI client collapses into this single message string.","triggerScenarios":"CometAPI rejecting the request due to an invalid model, insufficient credits/quota, malformed message payload, API key authentication failure, or a network timeout; CometAPI returning a non-OpenAI-schema error body that the SDK cannot parse.","commonSituations":"Exhausted CometAPI credit balance producing a 402/403; transient CometAPI gateway errors (502/503) during peak load; the model being valid per the cache but disabled server-side; proxies or firewalls intercepting the request to api.cometapi.com.","solutions":["Inspect the raw e.message — CometAPI errors typically include the HTTP status and a reason string.","Check the CometAPI dashboard for remaining quota/credits and API key status.","If the error is a transient 5xx, retry the request with exponential backoff.","Patch the catch to preserve the SDK error object rather than rewrapping into a plain Error."],"exampleFix":"// before\n.catch((e) => {\n  throw new Error(e.message);\n})\n\n// after\n.catch((e) => {\n  throw e; // preserve status code and structured error","handlingStrategy":"retry","validationCode":null,"typeGuard":"/** OpenAI SDK errors carry numeric `status` and an `error` object. */\nfunction isOpenAiSdkError(e) {\n  return e instanceof Error && typeof e.status === 'number';\n}","tryCatchPattern":"try {\n  return await comet.getChatCompletion(messages, { temperature });\n} catch (e) {\n  if (/429|rate|quota|insufficient/i.test(e.message)) {\n    await sleep(2000 * attempt);\n    return retry();\n  }\n  if (/401|403|unauthorized/i.test(e.message))\n    throw new Error('CometAPI key invalid — check COMETAPI_LLM_API_KEY and account credits');\n  throw e;\n}","preventionTips":["Monitor CometAPI credit balance and set up low-balance alerts.","Implement exponential backoff for transient 5xx/429 errors.","Log the full error object during development since e.message alone may omit the status code."],"tags":["cometapi","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"}