{"record":{"id":"c9475694b4c67cd5","repo":"Mintplex-Labs/anything-llm","slug":"litellm-must-have-a-valid-base-path-to-use-for-the","errorCode":null,"errorMessage":"LiteLLM must have a valid base path to use for the api.","messagePattern":"LiteLLM must have a valid base path to use for the api\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/liteLLM/index.js","lineNumber":14,"sourceCode":"const { NativeEmbedder } = require(\"../../EmbeddingEngines/native\");\nconst {\n  LLMPerformanceMonitor,\n} = require(\"../../helpers/chat/LLMPerformanceMonitor\");\nconst {\n  handleDefaultStreamResponseV2,\n  formatChatHistory,\n} = require(\"../../helpers/chat/responses\");\n\nclass LiteLLM {\n  constructor(embedder = null, modelPreference = null) {\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    if (!process.env.LITE_LLM_BASE_PATH)\n      throw new Error(\n        \"LiteLLM must have a valid base path to use for the api.\"\n      );\n\n    this.className = \"LiteLLM\";\n    this.basePath = process.env.LITE_LLM_BASE_PATH;\n    this.openai = new OpenAIApi({\n      baseURL: this.basePath,\n      apiKey: process.env.LITE_LLM_API_KEY ?? null,\n    });\n    this.model = modelPreference ?? process.env.LITE_LLM_MODEL_PREF ?? null;\n\n    if (!this.model) throw new Error(\"LiteLLM 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","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/liteLLM/index.js#L1-L32","documentation":"LiteLLM's provider class throws at construction when LITE_LLM_BASE_PATH is unset. LiteLLM is a self-hosted proxy that exposes an OpenAI-compatible API (default port 4000), and this base URL is required because the class routes all requests through it via the OpenAI SDK. The check is eager: selecting the LiteLLM provider with the var missing fails before any chat call.","triggerScenarios":"Choosing 'LiteLLM' as the LLM provider while LITE_LLM_BASE_PATH is absent from the server process env. Common when the LiteLLM proxy container isn't running, is on another port, or when AnythingLLM runs in Docker and points at localhost instead of host.docker.internal / the proxy's service name.","commonSituations":"docker-compose setups where anythingllm and litellm are separate services and the URL was never wired (should be http://litellm:4000 within the same network); port drift from LiteLLM's default 4000; forgetting the scheme (//localhost:4000 fails URL parsing downstream); LITE_LLM_API_KEY set but base path omitted.","solutions":["Start the LiteLLM proxy and verify: curl http://127.0.0.1:4000/v1/models -H \"Authorization: Bearer $LITE_LLM_MASTER_KEY\".","Set LITE_LLM_BASE_PATH=http://127.0.0.1:4000 (or http://litellm:4000 inside a compose network) in backend .env.","Set LITE_LLM_MODEL_PREF (required next, see the model error) and LITE_LLM_API_KEY if the proxy enforces its master key.","Restart the AnythingLLM server after saving env changes."],"exampleFix":"# before (.env)\nLITE_LLM_MODEL_PREF=gpt-4o-mini\n\n# after (.env)\nLITE_LLM_BASE_PATH=http://127.0.0.1:4000\nLITE_LLM_API_KEY=sk-1234\nLITE_LLM_MODEL_PREF=gpt-4o-mini","handlingStrategy":"validation","validationCode":"if (!process.env.LITE_LLM_BASE_PATH) throw new Error(\"LITE_LLM_BASE_PATH missing\");\ntry { new URL(process.env.LITE_LLM_BASE_PATH); } catch { throw new Error(\"LITE_LLM_BASE_PATH must include scheme, e.g. http://127.0.0.1:4000\"); }","typeGuard":null,"tryCatchPattern":"try {\n  new LiteLLM(embedder, model);\n} catch (e) {\n  if (/valid base path/i.test(e.message)) return promptEnvSetup(\"LITE_LLM_BASE_PATH\");\n  throw e;\n}","preventionTips":["Health-check the proxy (GET /v1/models with the master key) before selecting the provider.","In compose networks, use the service hostname (http://litellm:4000) instead of localhost.","Keep LITE_LLM_BASE_PATH, LITE_LLM_API_KEY, LITE_LLM_MODEL_PREF as a validated group at boot."],"tags":["litellm","anythingllm","proxy","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"}