{"record":{"id":"45e0054ed9fa3b0e","repo":"Mintplex-Labs/anything-llm","slug":"no-foundry-base-path-was-set","errorCode":null,"errorMessage":"No Foundry Base Path was set.","messagePattern":"No Foundry Base Path was set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"server/utils/AiProviders/foundry/index.js","lineNumber":30,"sourceCode":"const { OpenAI: OpenAIApi } = require(\"openai\");\nconst ToolCallTextFilter = require(\"./toolCallFilter.js\");\n\nclass FoundryLLM {\n  /**\n   * The largest context window we will select on the user's behalf.\n   * Foundry runs on the user's own machine with no performance setting, so a\n   * model advertising 128K would make an average laptop crawl. A user who\n   * explicitly sets a larger limit still gets it, up to the model's real window.\n   * @type {number}\n   */\n  static MAX_DEFAULT_CONTEXT_WINDOW = 16_000;\n\n  /** @see FoundryLLM.cacheContextWindows */\n  static modelContextWindows = {};\n\n  constructor(embedder = null, modelPreference = null) {\n    if (!process.env.FOUNDRY_BASE_PATH)\n      throw new Error(\"No Foundry Base Path was set.\");\n\n    this.className = \"FoundryLLM\";\n    this.model = modelPreference || process.env.FOUNDRY_MODEL_PREF;\n    this.openai = new OpenAIApi({\n      baseURL: parseFoundryBasePath(process.env.FOUNDRY_BASE_PATH),\n      apiKey: null,\n    });\n\n    this.embedder = embedder ?? new NativeEmbedder();\n    this.defaultTemp = 0.7;\n    this.limits = null;\n    FoundryLLM.cacheContextWindows(true);\n    this.#log(`Loaded with model: ${this.model}`);\n  }\n\n  static #slog(text, ...args) {\n    console.log(`\\x1b[36m[FoundryLLM]\\x1b[0m ${text}`, ...args);\n  }","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/foundry/index.js#L12-L48","documentation":"Thrown by the FoundryLLM constructor when process.env.FOUNDRY_BASE_PATH is unset. Foundry Local is Microsoft's on-device inference runtime that exposes an OpenAI-compatible HTTP endpoint; AnythingLLM needs that endpoint URL (later passed through parseFoundryBasePath) to construct its internal OpenAI client. Without a base path there is no server to route completions to, so the provider refuses to instantiate.","triggerScenarios":"Constructing `new FoundryLLM(embedder, modelPreference)` at provider-selection time while FOUNDRY_BASE_PATH is absent from process.env. In AnythingLLM this fires the moment a user picks the Foundry Local LLM provider but never supplied the endpoint in the UI or .env.","commonSituations":"Foundry Local not yet installed or not running; the .env file has no FOUNDRY_BASE_PATH line; the user selected Foundry as the provider before finishing setup; a Docker/PM2 deployment that did not pass the env var through to the process.","solutions":["Set FOUNDRY_BASE_PATH in .env (or the provider settings UI) to your Foundry Local OpenAI endpoint, e.g. http://localhost:5273/v1","Confirm Foundry Local is installed and running with `foundry --status` (or the tray app) before starting AnythingLLM","Restart the AnythingLLM server so the new environment variable is loaded into process.env","Verify the endpoint with `curl $FOUNDRY_BASE_PATH/models` to confirm it answers before configuring AnythingLLM"],"exampleFix":"// before (server/.env has no Foundry vars)\n//   selecting Foundry Local in the UI throws on construction\n\n// after\n// server/.env\n//   FOUNDRY_BASE_PATH=http://localhost:5273/v1\n//   FOUNDRY_MODEL_PREF=Phi-3-mini-4k-instruct-cuda","handlingStrategy":"validation","validationCode":"// before constructing the provider\nfunction canUseFoundry() {\n  return Boolean(process.env.FOUNDRY_BASE_PATH);\n}\nif (!canUseFoundry()) {\n  // surface a user-facing config error instead of letting the constructor throw\n  throw new ConfigError('Set FOUNDRY_BASE_PATH to your Foundry Local endpoint.');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep all FOUNDRY_* keys in a single block in .env and validate that block on startup","Add a pre-flight check that pings $FOUNDRY_BASE_PATH/models before registering the provider","Surface missing-env errors in the provider-settings UI rather than at first chat"],"tags":["foundry","configuration","environment-variables","local-inference","constructor"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}