Mintplex-Labs/anything-llm · error
e.message
Error message
e.message
What it means
Not a fixed message: this is the .catch attached to openai.chat.completions.create re-throwing the upstream ApiPie (OpenAI-compatible) error's message verbatim. Whatever the endpoint returned - 401 incorrect APIPIE_LLM_API_KEY, 429 quota, 404 model not found, socket timeouts, oversized prompts - becomes the Error text. Because the promise rejects before completion, LLMPerformanceMonitor never records metrics for the call.
Solutions
- Match the error text to a status: 401 -> fix the key, 429 -> back off, 404 -> repick the model, network -> check egress
- Verify APIPIE_LLM_API_KEY with a direct curl to https://apipie.ai/v1/models
- Retry with exponential backoff on 429/5xx
- Trim workspace context if context-length errors appear
Example fix
// before
const result = await apipie.getChatCompletion(messages);
// after
try {
const result = await apipie.getChatCompletion(messages);
} catch (e) {
if (/429|rate/i.test(e.message)) {
await new Promise((r) => setTimeout(r, 5000));
return apipie.getChatCompletion(messages);
}
throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
// Cheap liveness + auth probe before a long chat call
try {
await apipie.openai.models.list();
} catch (e) {
return res.status(502).json({ error: `ApiPie unreachable or key invalid: ${e.message}` });
} Try / catch
try {
const result = await apipie.getChatCompletion(messages);
} catch (e) {
if (/401|api key/i.test(e.message)) handleBadKey();
else if (/429|quota|rate/i.test(e.message)) return retryWithBackoff(fn);
else if (/404|model/i.test(e.message)) handleBadModel();
else throw e;
} Prevention
- Probe the key with models.list before starting long conversations
- Classify upstream errors by inspecting the message text (it is verbatim from the API)
- Bound prompt size to avoid context-length rejections
- Retry transient statuses only, with backoff
When it happens
Trigger: Invalid or expired ApiPie key (401); model removed between validation and the call (404); rate/quota limits (429); network failure reaching apipie.ai; prompt exceeding the upstream model's context window.
Common situations: Key rotation without updating provider settings; aggregator or upstream provider outages; long workspace context pushed into the prompt; regional or firewall blocks on apipie.ai.
Related errors
- AnthropicLLM::getChatCompletion failed to communicate with…
- Mistral Failed to embed
- No user prompt found. Must be last element in message array…
- An error occurred while deleting the model
- ApiPie chat: is not valid for chat completion!
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/82f5c2a0b30a0058.
Report an issue: GitHub.
Appendix: source
Thrown at server/utils/AiProviders/apipie/index.js:204
},
];
}
async getChatCompletion(messages = null, { temperature = 0.7 }) {
if (!(await this.isValidChatCompletionModel(this.model)))
throw new Error(
`ApiPie 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 || 0) / result.duration,
duration: result.duration,View on GitHub (pinned to 3aec848f28)