Mintplex-Labs/anything-llm · error · Error

No Foundry Base Path was set.

Error message

No Foundry Base Path was set.

What it means

The FoundryLLM constructor throws when the FOUNDRY_BASE_PATH environment variable is unset. Foundry Local is a user-hosted, OpenAI-compatible service, and this base path is the only way to locate it (there is no API key; apiKey is passed as null). Since the provider is constructed per request, the error appears when a chat selects Foundry Local as its LLM.

Solutions

  1. Set FOUNDRY_BASE_PATH to your Foundry Local endpoint (e.g. http://localhost:5273/v1) in .env and restart the server
  2. Run `foundry model list` or check the Foundry Local service is actually listening, then use that port in the path
  3. In Docker, point FOUNDRY_BASE_PATH at host.docker.internal:<port> instead of localhost and pass the var into the container
  4. Double-check the exact variable name FOUNDRY_BASE_PATH

Example fix

# before (.env)
# FOUNDRY_BASE_PATH not set

# after (.env)
FOUNDRY_BASE_PATH=http://localhost:5273/v1
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.FOUNDRY_BASE_PATH) {
  return setupError("Set FOUNDRY_BASE_PATH (e.g. http://localhost:5273/v1) to use Foundry Local.");
}
const llm = new FoundryLLM(embedder, modelPref);

Try / catch

try {
  const llm = new FoundryLLM(embedder, modelPref);
} catch (err) {
  if (err.message === "No Foundry Base Path was set.") {
    return respond("Configure FOUNDRY_BASE_PATH before using Foundry Local.");
  }
  throw err;
}

Prevention

When it happens

Trigger: Choosing Foundry Local as the workspace/provider LLM while FOUNDRY_BASE_PATH is not in the server environment. Typical valid value is the local service URL such as http://localhost:5273/v1 (the code normalizes it via parseFoundryBasePath).

Common situations: Foundry Local installed but AnythingLLM started without the env var (var added to .env after the server launched); Docker deployment where the host's localhost is wrong or the var was never passed into the container; typo'd variable name like FOUNDRY_ENDPOINT.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at server/utils/AiProviders/foundry/index.js:30

const { OpenAI: OpenAIApi } = require("openai");
const ToolCallTextFilter = require("./toolCallFilter.js");

class FoundryLLM {
  /**
   * The largest context window we will select on the user's behalf.
   * Foundry runs on the user's own machine with no performance setting, so a
   * model advertising 128K would make an average laptop crawl. A user who
   * explicitly sets a larger limit still gets it, up to the model's real window.
   * @type {number}
   */
  static MAX_DEFAULT_CONTEXT_WINDOW = 16_000;

  /** @see FoundryLLM.cacheContextWindows */
  static modelContextWindows = {};

  constructor(embedder = null, modelPreference = null) {
    if (!process.env.FOUNDRY_BASE_PATH)
      throw new Error("No Foundry Base Path was set.");

    this.className = "FoundryLLM";
    this.model = modelPreference || process.env.FOUNDRY_MODEL_PREF;
    this.openai = new OpenAIApi({
      baseURL: parseFoundryBasePath(process.env.FOUNDRY_BASE_PATH),
      apiKey: null,
    });

    this.embedder = embedder ?? new NativeEmbedder();
    this.defaultTemp = 0.7;
    this.limits = null;
    FoundryLLM.cacheContextWindows(true);
    this.#log(`Loaded with model: ${this.model}`);
  }

  static #slog(text, ...args) {
    console.log(`\x1b[36m[FoundryLLM]\x1b[0m ${text}`, ...args);
  }

View on GitHub (pinned to 3aec848f28)