Mintplex-Labs/anything-llm · error · Error
${e.message}
Error message
${e.message} What it means
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.
Source
Thrown at server/utils/AiProviders/cometapi/index.js:210
},
];
}
async getChatCompletion(messages = null, { temperature = 0.7 }) {
if (!(await this.isValidChatCompletionModel(this.model)))
throw new Error(
`CometAPI 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
- 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.
Example fix
// before
.catch((e) => {
throw new Error(e.message);
})
// after
.catch((e) => {
throw e; // preserve status code and structured error Defensive patterns
Strategy: retry
Type guard
/** OpenAI SDK errors carry numeric `status` and an `error` object. */
function isOpenAiSdkError(e) {
return e instanceof Error && typeof e.status === 'number';
} Try / catch
try {
return await comet.getChatCompletion(messages, { temperature });
} catch (e) {
if (/429|rate|quota|insufficient/i.test(e.message)) {
await sleep(2000 * attempt);
return retry();
}
if (/401|403|unauthorized/i.test(e.message))
throw new Error('CometAPI key invalid — check COMETAPI_LLM_API_KEY and account credits');
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/981cbaab5da4258f.
Report an issue: GitHub.