Mintplex-Labs/anything-llm · error
No ApiPie LLM API key was set.
Error message
No ApiPie LLM API key was set.
What it means
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.
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
Example fix
# before # no APIPIE_LLM_API_KEY in the environment # after export APIPIE_LLM_API_KEY=your-key # or set it in System Settings -> AI Providers -> ApiPie
Defensive patterns
Strategy: validation
Validate before calling
function canUseApiPie() {
return Boolean(process.env.APIPIE_LLM_API_KEY);
}
if (!canUseApiPie()) {
return res.status(503).json({ error: "ApiPie provider is not configured" });
}
const llm = new ApiPieLLM(embedder, modelPref); Try / catch
try {
const llm = new ApiPieLLM(embedder, modelPref);
} catch (e) {
if (/No ApiPie LLM API key/i.test(e.message)) {
return res.status(503).json({ error: "Set APIPIE_LLM_API_KEY in provider settings" });
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
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
- No Anthropic API key was set.
- No Azure API key was set.
- No Azure API endpoint was set.
- No Gemini API key was set.
- No Groq API key was set.
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/590e53aa1d7c7b3e.
Report an issue: GitHub.
Appendix: source
Thrown at server/utils/AiProviders/apipie/index.js:24
formatChatHistory,
} = require("../../helpers/chat/responses");
const fs = require("fs");
const path = require("path");
const { safeJsonParse } = require("../../http");
const {
LLMPerformanceMonitor,
} = require("../../helpers/chat/LLMPerformanceMonitor");
const cacheFolder = path.resolve(
process.env.STORAGE_DIR
? path.resolve(process.env.STORAGE_DIR, "models", "apipie")
: path.resolve(__dirname, `../../../storage/models/apipie`)
);
class ApiPieLLM {
constructor(embedder = null, modelPreference = null) {
if (!process.env.APIPIE_LLM_API_KEY)
throw new Error("No ApiPie LLM API key was set.");
this.className = "ApiPieLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.basePath = "https://apipie.ai/v1";
this.openai = new OpenAIApi({
baseURL: this.basePath,
apiKey: process.env.APIPIE_LLM_API_KEY ?? null,
});
this.model =
modelPreference ||
process.env.APIPIE_LLM_MODEL_PREF ||
"openrouter/mistral-7b-instruct";
this.limits = {
history: this.promptWindowLimit() * 0.15,
system: this.promptWindowLimit() * 0.15,
user: this.promptWindowLimit() * 0.7,
};
View on GitHub (pinned to 3aec848f28)