{"record":{"id":"590e53aa1d7c7b3e","repo":"Mintplex-Labs/anything-llm","slug":"no-apipie-llm-api-key-was-set","errorCode":null,"errorMessage":"No ApiPie LLM API key was set.","messagePattern":"No ApiPie LLM API key was set\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/apipie/index.js","lineNumber":24,"sourceCode":"  formatChatHistory,\n} = require(\"../../helpers/chat/responses\");\nconst fs = require(\"fs\");\nconst path = require(\"path\");\nconst { safeJsonParse } = require(\"../../http\");\nconst {\n  LLMPerformanceMonitor,\n} = require(\"../../helpers/chat/LLMPerformanceMonitor\");\n\nconst cacheFolder = path.resolve(\n  process.env.STORAGE_DIR\n    ? path.resolve(process.env.STORAGE_DIR, \"models\", \"apipie\")\n    : path.resolve(__dirname, `../../../storage/models/apipie`)\n);\n\nclass ApiPieLLM {\n  constructor(embedder = null, modelPreference = null) {\n    if (!process.env.APIPIE_LLM_API_KEY)\n      throw new Error(\"No ApiPie LLM API key was set.\");\n\n    this.className = \"ApiPieLLM\";\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    this.basePath = \"https://apipie.ai/v1\";\n    this.openai = new OpenAIApi({\n      baseURL: this.basePath,\n      apiKey: process.env.APIPIE_LLM_API_KEY ?? null,\n    });\n    this.model =\n      modelPreference ||\n      process.env.APIPIE_LLM_MODEL_PREF ||\n      \"openrouter/mistral-7b-instruct\";\n    this.limits = {\n      history: this.promptWindowLimit() * 0.15,\n      system: this.promptWindowLimit() * 0.15,\n      user: this.promptWindowLimit() * 0.7,\n    };\n","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/apipie/index.js#L6-L42","documentation":"The ApiPieLLM constructor throws when process.env.APIPIE_LLM_API_KEY is unset, before the OpenAI-compatible client targeting https://apipie.ai/v1 is built. The key is normally saved through the ApiPie provider settings UI (persisted in storage) or injected as an env var. Selecting ApiPie without credentials fails provider construction on the first completion request.","triggerScenarios":"Selecting ApiPie as the LLM provider without saving a key; docker deployments missing -e APIPIE_LLM_API_KEY and the storage volume; env set in a shell but not in the process manager unit; key name typos like APIPIE_API_KEY.","commonSituations":"Container recreation dropping env; .env not loaded in production; per-node env drift in multi-instance setups; key configured for a different environment (dev vs prod).","solutions":["Set the key in System Settings -> AI Providers -> ApiPie or export APIPIE_LLM_API_KEY","Pass the env into containers explicitly (-e or env_file) and mount the storage volume","Restart the server after setting the variable","Verify with a cheap authenticated call: GET https://apipie.ai/v1/models with the key"],"exampleFix":"# before\n# no APIPIE_LLM_API_KEY in the environment\n\n# after\nexport APIPIE_LLM_API_KEY=your-key\n# or set it in System Settings -> AI Providers -> ApiPie","handlingStrategy":"validation","validationCode":"function canUseApiPie() {\n  return Boolean(process.env.APIPIE_LLM_API_KEY);\n}\nif (!canUseApiPie()) {\n  return res.status(503).json({ error: \"ApiPie provider is not configured\" });\n}\nconst llm = new ApiPieLLM(embedder, modelPref);","typeGuard":null,"tryCatchPattern":"try {\n  const llm = new ApiPieLLM(embedder, modelPref);\n} catch (e) {\n  if (/No ApiPie LLM API key/i.test(e.message)) {\n    return res.status(503).json({ error: \"Set APIPIE_LLM_API_KEY in provider settings\" });\n  }\n  throw e;\n}","preventionTips":["Save the key via the provider settings UI so it persists in storage","Pass env vars explicitly to containers and service managers","Probe credentials cheaply with GET https://apipie.ai/v1/models after configuring"],"tags":["apipie","api-key","environment","configuration"],"backgroundTag":"missing-env-var","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"}