{"record":{"id":"d0a829932f0e724d","repo":"Mintplex-Labs/anything-llm","slug":"koboldcpp-must-have-a-valid-base-path-to-use-for-t","errorCode":null,"errorMessage":"KoboldCPP must have a valid base path to use for the api.","messagePattern":"KoboldCPP must have a valid base path to use for the api\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/koboldCPP/index.js","lineNumber":16,"sourceCode":"const { NativeEmbedder } = require(\"../../EmbeddingEngines/native\");\nconst {\n  clientAbortedHandler,\n  writeResponseChunk,\n  formatChatHistory,\n} = require(\"../../helpers/chat/responses\");\nconst {\n  LLMPerformanceMonitor,\n} = require(\"../../helpers/chat/LLMPerformanceMonitor\");\nconst { v4: uuidv4 } = require(\"uuid\");\n\nclass KoboldCPPLLM {\n  constructor(embedder = null, modelPreference = null) {\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    if (!process.env.KOBOLD_CPP_BASE_PATH)\n      throw new Error(\n        \"KoboldCPP must have a valid base path to use for the api.\"\n      );\n\n    this.className = \"KoboldCPPLLM\";\n    this.basePath = process.env.KOBOLD_CPP_BASE_PATH;\n    this.openai = new OpenAIApi({\n      baseURL: this.basePath,\n      apiKey: null,\n    });\n    this.model = modelPreference ?? process.env.KOBOLD_CPP_MODEL_PREF ?? null;\n    if (!this.model) throw new Error(\"KoboldCPP must have a valid model set.\");\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();","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/koboldCPP/index.js#L1-L34","documentation":"KoboldCPPLLM's constructor throws when KOBOLD_CPP_BASE_PATH is unset, because unlike cloud providers KoboldCPP is a user-hosted OpenAI-compatible endpoint with no default URL. The value becomes the OpenAI SDK baseURL (apiKey is explicitly null), so any chat/embedding operation needs it. AnythingLLM validates this at provider construction rather than at first HTTP call.","triggerScenarios":"Selecting KoboldCPP as the LLM provider while KOBOLD_CPP_BASE_PATH is missing from the server process env. Typically the KoboldCPP local server (e.g., http://127.0.0.1:5001) is not running yet, the env var was never added, or the URL points at the wrong port when the user copied a template for a different tool (e.g., the old KoboldAI horizon API port).","commonSituations":"Fresh local install where the user launched AnythingLLM before starting KoboldCPP; docker deployments where the host's localhost URL must be host.docker.internal, not localhost; port confusion between the KoboldCPP UI port and its OpenAI-compatible /v1 endpoint; trailing-path mistakes (parseLMStudioBasePath-style normalization is not applied here — the raw URL is used, so include the full base).","solutions":["Start KoboldCPP and confirm its OpenAI-compatible endpoint responds (curl http://127.0.0.1:5001/v1/models).","Set KOBOLD_CPP_BASE_PATH to that base URL, e.g. KOBOLD_CPP_BASE_PATH=http://127.0.0.1:5001/v1, in the backend .env.","Docker users: use http://host.docker.internal:5001/v1 (or the host LAN IP) since localhost inside the container is the container itself.","Restart the AnythingLLM server/container so the new env is picked up.","Keep KoboldCPP's 'Launch API server' option enabled so /v1 exists."],"exampleFix":"# before (.env) — nothing set\n\n# after (.env)\nKOBOLD_CPP_BASE_PATH=http://127.0.0.1:5001/v1\nKOBOLD_CPP_MODEL_PREF=<model tag shown in KoboldCPP>","handlingStrategy":"validation","validationCode":"function assertKoboldConfig() {\n  const base = process.env.KOBOLD_CPP_BASE_PATH;\n  if (!base) throw new Error(\"KOBOLD_CPP_BASE_PATH missing\");\n  try { new URL(base); } catch { throw new Error(`KOBOLD_CPP_BASE_PATH not a valid URL: ${base}`); }\n}","typeGuard":null,"tryCatchPattern":"try {\n  llm = new KoboldCPPLLM(embedder, model);\n} catch (e) {\n  if (/valid base path/i.test(e.message)) return guideUserToEnv(\"KOBOLD_CPP_BASE_PATH\");\n  throw e;\n}","preventionTips":["Health-check the KoboldCPP OpenAI endpoint (/v1/models) before constructing the provider.","In Docker, always use host.docker.internal or the host IP for locally served models.","Keep all KOBOLD_CPP_* vars together in .env so the base path is never configured alone.","Url-encode the value and include the full base path you verified with curl."],"tags":["koboldcpp","anythingllm","local-llm","env-var","base-url","configuration"],"backgroundTag":"missing-base-url","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"}