Mintplex-Labs/anything-llm · error · Error
e.message
Error message
e.message
What it means
Same re-wrap anti-pattern: getChatCompletion's .catch flattens any upstream Moonshot API error to a plain Error(e.message). Note Moonshot's getChatCompletion skips the isValidChatCompletionModel pre-check entirely (unlike Minimax/Mistral/Novita) and goes straight to the call, then returns null on a choices-less response. So this catch is the only error boundary for the request.
Source
Thrown at server/utils/AiProviders/moonshotAi/index.js:121
];
}
async compressMessages(promptArgs = {}, rawHistory = []) {
const { messageArrayCompressor } = require("../../helpers/chat");
const messageArray = this.constructPrompt(promptArgs);
return await messageArrayCompressor(this, messageArray, rawHistory);
}
async getChatCompletion(messages = null, { temperature = 0.7 }) {
const result = await LLMPerformanceMonitor.measureAsyncFunction(
this.openai.chat.completions
.create({
model: this.model,
messages,
temperature,
})
.catch((e) => {
throw new Error(e.message);
})
);
if (
!Object.prototype.hasOwnProperty.call(result.output, "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
- Read the message for the upstream detail (often includes the real cause).
- If context-length related, switch to moonshot-v1-32k or 128k, or trim history.
- If auth-related, verify MOONSHOT_AI_API_KEY.
- Add backoff/retry for 429/5xx text.
Example fix
// before
.catch((e) => {
throw new Error(e.message);
})
// after
.catch((e) => {
const err = new Error(`Moonshot chat failed (${e?.status}): ${e.message}`);
err.cause = e;
err.status = e?.status;
throw err;
}) Defensive patterns
Strategy: retry
Try / catch
try {
await llm.getChatCompletion(messages, { temperature });
} catch (e) {
const msg = e.message || '';
if (/context.*(length|window)|too many tokens/i.test(msg)) { /* trim history or use a larger model */ }
else if (/429|rate/i.test(msg)) { /* backoff */ }
else if (/401|api key/i.test(msg)) { /* rotate key */ }
} Prevention
- Pick the right moonshot-v1 window (8k/32k/128k) for your history size — Moonshot enforces it strictly.
- Patch the catch to retain e.status/e.cause.
- Compress chat history before sending to stay under the limit.
When it happens
Trigger: Any upstream failure from openai.chat.completions.create against api.moonshot.ai: 401, 429, 400 (e.g. context length exceeded on moonshot-v1-8k/32k), timeout, or 5xx.
Common situations: Invalid Moonshot key; exceeding the model's context window (Moonshot enforces per-model token limits); rate limiting; transient outage; the re-wrap hiding whether it was a context-length error vs auth.
Related errors
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/6fb6155478667b8d.
Report an issue: GitHub.