Mintplex-Labs/anything-llm · error

LiteLLM must have a valid base path to use for the api.

Error message

LiteLLM must have a valid base path to use for the api.

What it means

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.

Solutions

  1. Start the LiteLLM proxy and verify: curl http://127.0.0.1:4000/v1/models -H "Authorization: Bearer $LITE_LLM_MASTER_KEY".
  2. Set LITE_LLM_BASE_PATH=http://127.0.0.1:4000 (or http://litellm:4000 inside a compose network) in backend .env.
  3. Set LITE_LLM_MODEL_PREF (required next, see the model error) and LITE_LLM_API_KEY if the proxy enforces its master key.
  4. Restart the AnythingLLM server after saving env changes.

Example fix

# before (.env)
LITE_LLM_MODEL_PREF=gpt-4o-mini

# after (.env)
LITE_LLM_BASE_PATH=http://127.0.0.1:4000
LITE_LLM_API_KEY=sk-1234
LITE_LLM_MODEL_PREF=gpt-4o-mini
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.LITE_LLM_BASE_PATH) throw new Error("LITE_LLM_BASE_PATH missing");
try { 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"); }

Try / catch

try {
  new LiteLLM(embedder, model);
} catch (e) {
  if (/valid base path/i.test(e.message)) return promptEnvSetup("LITE_LLM_BASE_PATH");
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/c9475694b4c67cd5. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/AiProviders/liteLLM/index.js:14

const { NativeEmbedder } = require("../../EmbeddingEngines/native");
const {
  LLMPerformanceMonitor,
} = require("../../helpers/chat/LLMPerformanceMonitor");
const {
  handleDefaultStreamResponseV2,
  formatChatHistory,
} = require("../../helpers/chat/responses");

class LiteLLM {
  constructor(embedder = null, modelPreference = null) {
    const { OpenAI: OpenAIApi } = require("openai");
    if (!process.env.LITE_LLM_BASE_PATH)
      throw new Error(
        "LiteLLM must have a valid base path to use for the api."
      );

    this.className = "LiteLLM";
    this.basePath = process.env.LITE_LLM_BASE_PATH;
    this.openai = new OpenAIApi({
      baseURL: this.basePath,
      apiKey: process.env.LITE_LLM_API_KEY ?? null,
    });
    this.model = modelPreference ?? process.env.LITE_LLM_MODEL_PREF ?? null;

    if (!this.model) throw new Error("LiteLLM must have a valid model set.");
    this.limits = {
      history: this.promptWindowLimit() * 0.15,
      system: this.promptWindowLimit() * 0.15,
      user: this.promptWindowLimit() * 0.7,
    };

View on GitHub (pinned to 3aec848f28)