{"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/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/genericOpenAi/index.js#L216-L252","documentation":"GenericOpenAiLLM.getChatCompletion rethrows e.message from the OpenAI SDK call against the arbitrary user-configured endpoint. The generic provider has isValidChatCompletionModel hard-coded to true ('short circuit since we have no idea if the model is valid'), so there is no pre-flight validation — any endpoint error (404 wrong path/model, 401 missing key, connection refused, non-OpenAI schema responses) arrives here raw. The max_tokens sent is GENERIC_OPEN_AI_MAX_TOKENS (default 1024).","triggerScenarios":"chat.completions.create failing against GENERIC_OPEN_AI_BASE_PATH: base path missing /v1 (404), model id not served by the endpoint, GENERIC_OPEN_AI_API_KEY required but unset/wrong, local service down (ECONNREFUSED), or the endpoint not actually OpenAI-compatible (SDK fails parsing).","commonSituations":"LM Studio/Ollama/vLLM not running or listening on a different port; path set to http://localhost:11434 without /v1; endpoint needs a key the user assumed optional; model renamed on the local server after the workspace pref was saved.","solutions":["Read the inner message: '404' → fix base path/model id; '401' → set GENERIC_OPEN_AI_API_KEY; 'ECONNREFUSED' → start the local service","Confirm the endpoint answers: curl <GENERIC_OPEN_AI_BASE_PATH>/models and match the model id exactly","Ensure the base path includes the version segment (usually /v1)","If the service has its own auth (e.g. bearer token), put it in GENERIC_OPEN_AI_API_KEY"],"exampleFix":"# before (.env)\nGENERIC_OPEN_AI_BASE_PATH=http://localhost:11434  # missing /v1 -> 404 at chat\n\n# after (.env)\nGENERIC_OPEN_AI_BASE_PATH=http://localhost:11434/v1","handlingStrategy":"try-catch","validationCode":"// generic provider can't validate models (isValidChatCompletionModel is always true),\n// so probe the endpoint yourself before chatting\nconst res = await fetch(`${process.env.GENERIC_OPEN_AI_BASE_PATH}/models`);\nif (!res.ok) throw new Error(`Endpoint unreachable or wrong base path (HTTP ${res.status}).`);\nconst { data } = await res.json();\nif (!data.some((m) => m.id === model)) throw new Error(`Model '${model}' not served by endpoint.`);","typeGuard":null,"tryCatchPattern":"try {\n  return await llm.getChatCompletion(messages);\n} catch (err) {\n  if (/ECONNREFUSED|fetch failed/i.test(err.message)) return respond(\"Local inference server is down — start it and retry.\");\n  if (/404/.test(err.message)) return respond(\"Wrong base path or model id — check /v1 and the model name.\");\n  if (/401|api key/i.test(err.message)) return respond(\"Endpoint requires GENERIC_OPEN_AI_API_KEY.\");\n  throw err;\n}","preventionTips":["Verify base path + model id with a /models probe when settings are saved","Keep local inference servers under a process supervisor so they restart automatically","Include the /v1 suffix in the configured base path"],"tags":["generic-openai","openai-compat","api-error-passthrough","local-inference"],"backgroundTag":"openai-api-error","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}