{"record":{"id":"a7fdf5100cb84a18","repo":"Mintplex-Labs/anything-llm","slug":"foundry-could-not-load-modelid-http-response","errorCode":null,"errorMessage":"Foundry could not load ${modelId} (HTTP ${response.status}). Is the model downloaded?","messagePattern":"Foundry could not load (.+?) \\(HTTP (.+?)\\)\\. Is the model downloaded\\?","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/foundry/models.js","lineNumber":141,"sourceCode":"   * so this has to happen before the first completion — otherwise a streaming\n   * request is answered with headers and then the connection is dropped.\n   * @param {string} modelId - Alias or fully-qualified variant id.\n   * @param {string} basePath\n   * @returns {Promise<{success: boolean, error: string|null}>}\n   */\n  static async loadModel(modelId, basePath = process.env.FOUNDRY_BASE_PATH) {\n    const origin = this.#originOf(basePath);\n    if (!origin || !modelId)\n      return { success: false, error: \"No Foundry service or model was set.\" };\n\n    try {\n      // Loading pulls a multi-GB model into memory, well past the probe timeout.\n      const response = await fetch(\n        `${origin}/models/load/${encodeURIComponent(modelId)}`,\n        { signal: AbortSignal.timeout(this.LOAD_TIMEOUT_MS) }\n      );\n      if (!response.ok)\n        throw new Error(\n          `Foundry could not load ${modelId} (HTTP ${response.status}). Is the model downloaded?`\n        );\n      return { success: true, error: null };\n    } catch (e) {\n      return { success: false, error: e.message };\n    }\n  }\n\n  /**\n   * Release a model from memory.\n   * @param {string} modelId\n   * @param {string} basePath\n   * @returns {Promise<boolean>}\n   */\n  static async unloadModel(modelId, basePath = process.env.FOUNDRY_BASE_PATH) {\n    const origin = this.#originOf(basePath);\n    if (!origin || !modelId) return false;\n    try {","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/foundry/models.js#L123-L159","documentation":"FoundryModels.loadModel issues GET <origin>/models/load/<modelId> with a long timeout (loading pulls multi-GB into memory) and throws this error when the service responds with a non-OK status. It is returned as { success: false, error } to the caller (assertModelLoaded, error 145), not thrown to user code directly. The 'Is the model downloaded?' hint reflects the most common cause: the catalog lists the model but bits were never pulled to disk.","triggerScenarios":"GET /models/load/<id> returning 404 (model not downloaded / unknown id), 400 (bad id form), or a 5xx when the Foundry service fails to allocate memory. Also triggered when the fetch itself aborts past LOAD_TIMEOUT_MS (then the catch returns the abort message instead), or when basePath/modelId are blank (the 'No Foundry service or model was set.' branch above).","commonSituations":"Model id copied from the catalog without running `foundry model download`; Foundry Local running an old version without that model; insufficient RAM so the load endpoint errors; modelId alias vs full-id mismatch (the caller also matches id.split(':')[0]).","solutions":["Download the model first: `foundry model download <modelId>` and confirm with `foundry model list`","Use the exact id the service reports (full 'ai/...' id, not a display alias)","Free memory or choose a smaller quantization; check Foundry Local logs for the 5xx reason","Update Foundry Local so its /models/load endpoint and catalog are current"],"exampleFix":"# before\n# -> Foundry could not load ai/phi-3.5-mini (HTTP 404). Is the model downloaded?\n\n# after\nfoundry model download ai/phi-3.5-mini-instruct\n# retry the chat message","handlingStrategy":"validation","validationCode":"// verify the model exists on the service before asking it to load\nconst res = await fetch(`${origin}/models`);\nconst { models } = await res.json();\nif (!models.some((m) => m.id === modelId)) {\n  throw new Error(`Model ${modelId} not present on Foundry — download it first.`);\n}\nconst { success, error } = await FoundryModels.loadModel(modelId);","typeGuard":null,"tryCatchPattern":"const { success, error } = await FoundryModels.loadModel(modelId);\nif (!success) {\n  if (/HTTP 404/.test(error)) return guideDownload(modelId); // permanent: needs `foundry model download`\n  if (/HTTP 5/.test(error)) return retryAfterDelay();        // service-side, may clear\n  throw new Error(`Foundry load failed: ${error}`);\n}","preventionTips":["Always run foundry model download before wiring a model id into AnythingLLM","Check /models on the Foundry service to confirm the id exists locally","Treat 404 as permanent and 5xx/timeout as transient — only retry the latter"],"tags":["foundry-local","model-load-failed","http-error","local-inference"],"backgroundTag":"model-load-failed","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}