{"record":{"id":"41ccbb313fb5987f","repo":"Mintplex-Labs/anything-llm","slug":"e-message-41ccbb","errorCode":null,"errorMessage":"e.message","messagePattern":"e\\.message","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/genericOpenAi/index.js","lineNumber":234,"sourceCode":"    if (process.env.GENERIC_OPEN_AI_REPORT_USAGE !== \"true\") return {};\n    return {\n      stream_options: {\n        include_usage: true,\n      },\n    };\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.openai.chat.completions\n        .create({\n          model: this.model,\n          messages,\n          temperature,\n          max_tokens: this.maxTokens,\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    const usage = {\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      duration: result.duration,\n    };\n    this.#extractLlamaCppTimings(result.output, usage);\n\n    return {","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/genericOpenAi/index.js#L216-L252","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n.catch((e) => { throw new Error(e.message); })\n\n// after\n.catch((e) => { throw e; })","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await llm.getChatCompletion(messages, { temperature });\n} catch (e) {\n  const msg = e.message;\n  if (/401|unauthor/i.test(msg)) throw new AuthError(msg);\n  if (/model_not_found|404/i.test(msg)) throw new UnknownModelError(msg);\n  if (/maximum context|too long/i.test(msg)) throw new ContextTooLongError(msg);\n  throw e;\n}","preventionTips":["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"],"tags":["generic-openai","openai-sdk","error-wrapping","chat-completion","network"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}