{"record":{"id":"e3bc824115df2cb1","repo":"Mintplex-Labs/anything-llm","slug":"textgenwebui-must-have-a-valid-base-path-to-use-fo","errorCode":null,"errorMessage":"TextGenWebUI must have a valid base path to use for the api.","messagePattern":"TextGenWebUI must have a valid base path to use for the api\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/textGenWebUI/index.js","lineNumber":14,"sourceCode":"const { NativeEmbedder } = require(\"../../EmbeddingEngines/native\");\nconst {\n  handleDefaultStreamResponseV2,\n  formatChatHistory,\n} = require(\"../../helpers/chat/responses\");\nconst {\n  LLMPerformanceMonitor,\n} = require(\"../../helpers/chat/LLMPerformanceMonitor\");\n\nclass TextGenWebUILLM {\n  constructor(embedder = null) {\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    if (!process.env.TEXT_GEN_WEB_UI_BASE_PATH)\n      throw new Error(\n        \"TextGenWebUI must have a valid base path to use for the api.\"\n      );\n\n    this.className = \"TextGenWebUILLM\";\n    this.basePath = process.env.TEXT_GEN_WEB_UI_BASE_PATH;\n    this.openai = new OpenAIApi({\n      baseURL: this.basePath,\n      apiKey: process.env.TEXT_GEN_WEB_UI_API_KEY ?? null,\n    });\n    this.model = null;\n    this.limits = {\n      history: this.promptWindowLimit() * 0.15,\n      system: this.promptWindowLimit() * 0.15,\n      user: this.promptWindowLimit() * 0.7,\n    };\n\n    this.embedder = embedder ?? new NativeEmbedder();\n    this.defaultTemp = 0.7;","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/textGenWebUI/index.js#L1-L32","documentation":"Thrown by the TextGenWebUILLM constructor when process.env.TEXT_GEN_WEB_UI_BASE_PATH is falsy. TextGenWebUI is a self-hosted OpenAI-compatible server (text-generation-webui with the openai extension), so its base URL is mandatory and there is no default. Note the constructor takes only (embedder) — there is no model arg; this.model is set to null.","triggerScenarios":"Instantiating `new TextGenWebUILLM(embedder)` with TEXT_GEN_WEB_UI_BASE_PATH unset/empty. The extension's URL (commonly http://127.0.0.1:5001/v1) must be configured before selecting this provider.","commonSituations":"text-generation-webui openai extension not started or started on a different port; variable named TEXT_GEN_WEB_UI_BASE_URL instead of _BASE_PATH; .env not reloaded; wrong host when AnythingLLM runs in a container separate from the webui host (127.0.0.1 vs the docker gateway).","solutions":["Start the text-generation-webui OpenAI extension and set TEXT_GEN_WEB_UI_BASE_PATH to its base (e.g. http://127.0.0.1:5001/v1) in server/.env.","Confirm reachability: `curl -s http://127.0.0.1:5001/v1/models`.","If AnythingLLM is containerised, point at the host IP / docker service name, not 127.0.0.1.","Restart AnythingLLM after saving .env."],"exampleFix":"// before\n// TEXT_GEN_WEB_UI_BASE_PATH unset -> throws\nconst llm = new TextGenWebUILLM(embedder);\n\n// after\n// server/.env\n// TEXT_GEN_WEB_UI_BASE_PATH=http://127.0.0.1:5001/v1\n// TEXT_GEN_WEB_UI_MODEL_TOKEN_LIMIT=4096\nconst llm = new TextGenWebUILLM(embedder);","handlingStrategy":"validation","validationCode":"function assertTextGenBasePath() {\n  const p = process.env.TEXT_GEN_WEB_UI_BASE_PATH;\n  if (!p || !p.trim()) {\n    throw new Error(\"TEXT_GEN_WEB_UI_BASE_PATH missing — start the text-generation-webui openai extension and set this (e.g. http://127.0.0.1:5001/v1)\");\n  }\n  try { new URL(p); } catch { throw new Error(`TEXT_GEN_WEB_UI_BASE_PATH is not a valid URL: ${p}`); }\n}\nassertTextGenBasePath();\nconst llm = new TextGenWebUILLM(embedder);","typeGuard":"function hasTextGenBasePath(env = process.env) {\n  if (typeof env.TEXT_GEN_WEB_UI_BASE_PATH !== \"string\" || !env.TEXT_GEN_WEB_UI_BASE_PATH.trim()) return false;\n  try { new URL(env.TEXT_GEN_WEB_UI_BASE_PATH); return true; } catch { return false; }\n}","tryCatchPattern":"let llm;\ntry {\n  llm = new TextGenWebUILLM(embedder);\n} catch (e) {\n  if (/valid base path/i.test(e.message)) {\n    return { ok: false, reason: \"missing-textgen-base-path\" };\n  }\n  throw e;\n}","preventionTips":["Boot-time probe the openai extension (GET <base>/models) and mark the provider unhealthy if unreachable.","Document the openai-extension requirement; the base webui port alone is not enough.","Use the docker-reachable host when AnythingLLM is containerised.","Restart AnythingLLM after changing .env."],"tags":["configuration","env","llm-provider","textgenwebui","constructor","self-hosted"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}