Mintplex-Labs/anything-llm · error · Error
e.message
Error message
e.message
What it means
Not a distinct error — the message is whatever the OpenAI SDK raised against the generic endpoint. The `.catch((e) => { throw new Error(e.message); })` wrapper keeps only the text, dropping the SDK error subclass and stack. Anything the arbitrary OpenAI-compatible server returns as a failure surfaces here.
Source
Thrown at server/utils/AiProviders/genericOpenAi/index.js:234
if (process.env.GENERIC_OPEN_AI_REPORT_USAGE !== "true") return {};
return {
stream_options: {
include_usage: true,
},
};
}
async getChatCompletion(messages = null, { temperature = 0.7 }) {
const result = await LLMPerformanceMonitor.measureAsyncFunction(
this.openai.chat.completions
.create({
model: this.model,
messages,
temperature,
max_tokens: this.maxTokens,
})
.catch((e) => {
throw new Error(e.message);
})
);
if (
!result.output.hasOwnProperty("choices") ||
result.output.choices.length === 0
)
return null;
const usage = {
prompt_tokens: result.output?.usage?.prompt_tokens || 0,
completion_tokens: result.output?.usage?.completion_tokens || 0,
total_tokens: result.output?.usage?.total_tokens || 0,
duration: result.duration,
};
this.#extractLlamaCppTimings(result.output, usage);
return {View on GitHub (pinned to 526360e320)
Solutions
- Read e.message for the server's actual error text
- Confirm the model id matches one from GET $BASE_PATH/models
- Lower GENERIC_OPEN_AI_MAX_TOKENS if the message mentions token limits
- Set GENERIC_OPEN_AI_API_KEY if the endpoint requires auth
Example fix
// before
.catch((e) => { throw new Error(e.message); })
// after
.catch((e) => { throw e; }) Defensive patterns
Strategy: try-catch
Try / catch
try {
return await llm.getChatCompletion(messages, { temperature });
} catch (e) {
const msg = e.message;
if (/401|unauthor/i.test(msg)) throw new AuthError(msg);
if (/model_not_found|404/i.test(msg)) throw new UnknownModelError(msg);
if (/maximum context|too long/i.test(msg)) throw new ContextTooLongError(msg);
throw e;
} Prevention
- Re-throw the original SDK error to preserve status code and class
- Pre-flight the model id against GET $BASE_PATH/models
- Bound max_tokens to the configured token limit
When it happens
Trigger: this.openai.chat.completions.create({ model, messages, temperature, max_tokens }) rejecting: server returned 4xx/5xx, model id unknown to that server, max_tokens exceeds the server's limit, auth header rejected, or the server is not actually OpenAI-compatible.
Common situations: Model id in GENERIC_OPEN_AI_MODEL_PREF not served by the endpoint; max_tokens too large for the local model; endpoint requires an API key but GENERIC_OPEN_AI_API_KEY is unset/wrong; server speaks a slightly different schema.
Related errors
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/41ccbb313fb5987f.
Report an issue: GitHub.