{"record":{"id":"319abd50cfe2234a","repo":"Mintplex-Labs/anything-llm","slug":"e-message-319abd","errorCode":null,"errorMessage":"${e.message}","messagePattern":"\\$\\{e\\.message\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/textGenWebUI/index.js","lineNumber":135,"sourceCode":"      prompt,\n      ...formatChatHistory(chatHistory, this.#generateContent),\n      {\n        role: \"user\",\n        content: this.#generateContent({ userPrompt, attachments }),\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        })\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    return {\n      textResponse: result.output.choices[0].message.content,\n      metrics: {\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        outputTps: result.output.usage?.completion_tokens / result.duration,\n        duration: result.duration,\n        model: this.model,","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/textGenWebUI/index.js#L117-L153","documentation":"Re-thrown from the OpenAI SDK rejection inside TextGenWebUILLM.getChatCompletion via `.catch((e) => { throw new Error(e.message); })`. Because TextGenWebUI isValidChatCompletionModel always returns true and this.model is null (the constructor hardcodes it), there is no pre-flight model check — so any server-side rejection (unknown model, auth, connection) surfaces here with only the message string.","triggerScenarios":"The text-generation-webui openai extension returns non-2xx or is unreachable during the create call: connection refused, 404 (no model loaded / wrong model name in the payload), 401 (api key required by the extension but TEXT_GEN_WEB_UI_API_KEY unset/wrong), 500 (model not loaded in the webui), or transport/abort errors.","commonSituations":"No model loaded in text-generation-webui when the request arrives; the extension is on a different port than TEXT_GEN_WEB_UI_BASE_PATH; the extension expects an api key but TEXT_GEN_WEB_UI_API_KEY is unset (the constructor passes null in that case); the webui process was restarted and the model was not reloaded; client aborted.","solutions":["Confirm a model is loaded in text-generation-webui and GET <base>/models returns it.","Verify the base path/port and that the openai extension is enabled: `curl -s http://127.0.0.1:5001/v1/models`.","If the extension requires auth, set TEXT_GEN_WEB_UI_API_KEY to match.","For transient connection resets, add bounded retry; for 'model not found', load the model in the webui first."],"exampleFix":"// before\nconst out = await llm.getChatCompletion(messages, { temperature: 0.7 });\n\n// after\ntry {\n  const out = await llm.getChatCompletion(messages, { temperature: 0.7 });\n} catch (err) {\n  if (/ECONNREFUSED|fetch failed/i.test(err.message)) throw new Error(\"TextGenWebUI unreachable — is the openai extension running?\", { cause: err });\n  if (/model/i.test(err.message)) throw new Error(\"No model loaded in text-generation-webui\", { cause: err });\n  throw err;\n}","handlingStrategy":"try-catch","validationCode":"async function assertTextGenReady(basePath, apiKey) {\n  // No client-side model check exists (this.model is null), so probe the server\n  const res = await fetch(`${basePath}/models`, {\n    headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : {},\n  });\n  if (!res.ok) throw new Error(`text-generation-webui openai extension not ready (${res.status}) at ${basePath}`);\n  const { data } = await res.json();\n  if (!data || !data.length) throw new Error(\"No model loaded in text-generation-webui\");\n}\nawait assertTextGenReady(process.env.TEXT_GEN_WEB_UI_BASE_PATH, process.env.TEXT_GEN_WEB_UI_API_KEY);","typeGuard":"function isTextGenReachableError(message) {\n  return typeof message === \"string\" && /ECONNREFUSED|fetch failed|socket hang up|timeout/i.test(message);\n}","tryCatchPattern":"try {\n  return await llm.getChatCompletion(messages, opts);\n} catch (e) {\n  if (/ECONNREFUSED|fetch failed/i.test(e.message)) throw new Error(\"TextGenWebUI unreachable — start the openai extension\", { cause: e });\n  if (/model/i.test(e.message)) throw new Error(\"No model loaded in text-generation-webui — load one first\", { cause: e });\n  if (/401|unauthorized/i.test(e.message)) throw new Error(\"TextGenWebUI api key mismatch\", { cause: e });\n  throw e;\n}","preventionTips":["TextGenWebUI does no client-side model validation, so probe GET <base>/models before sending chat traffic.","Ensure a model is loaded in text-generation-webui before AnythingLLM issues requests.","If the extension requires auth, set TEXT_GEN_WEB_UI_API_KEY to match.","Preserve the underlying SDK error with { cause: e } so status codes survive the wrapper."],"tags":["runtime","api-error","llm-provider","textgenwebui","network","self-hosted","error-wrapping"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}