Mintplex-Labs/anything-llm · error · Error
No Perplexity API key was set.
Error message
No Perplexity API key was set.
What it means
Thrown by the PerplexityLLM constructor when process.env.PERPLEXITY_API_KEY is falsy at instantiation time. AnythingLLM refuses to build the provider client without credentials because every downstream call would fail with a 401 anyway, so it fails fast. The provider is an OpenAI-compatible client pointed at https://api.perplexity.ai.
Source
Thrown at server/utils/AiProviders/perplexity/index.js:20
const { NativeEmbedder } = require("../../EmbeddingEngines/native");
const { isAbortError } = require("../../helpers/abortSignals");
const {
writeResponseChunk,
clientAbortedHandler,
} = require("../../helpers/chat/responses");
const {
LLMPerformanceMonitor,
} = require("../../helpers/chat/LLMPerformanceMonitor");
function perplexityModels() {
const { MODELS } = require("./models.js");
return MODELS || {};
}
class PerplexityLLM {
constructor(embedder = null, modelPreference = null) {
if (!process.env.PERPLEXITY_API_KEY)
throw new Error("No Perplexity API key was set.");
this.className = "PerplexityLLM";
const { OpenAI: OpenAIApi } = require("openai");
this.openai = new OpenAIApi({
baseURL: "https://api.perplexity.ai",
apiKey: process.env.PERPLEXITY_API_KEY ?? null,
});
this.model =
modelPreference ||
process.env.PERPLEXITY_MODEL_PREF ||
"llama-3-sonar-large-32k-online"; // Give at least a unique model to the provider as last fallback.
this.limits = {
history: this.promptWindowLimit() * 0.15,
system: this.promptWindowLimit() * 0.15,
user: this.promptWindowLimit() * 0.7,
};
this.embedder = embedder ?? new NativeEmbedder();View on GitHub (pinned to 526360e320)
Solutions
- Set PERPLEXITY_API_KEY in server/.env (or your process env) to a valid key from https://www.perplexity.ai/settings/api and restart the server.
- Verify the variable is actually loaded by the Node process: `node -e "console.log(Boolean(process.env.PERPLEXITY_API_KEY))"` run with the same env as the server.
- If running under Docker/compose, confirm the variable is passed through (env_file or environment: block) and the container was recreated after the change.
- Check for leading/trailing whitespace or quote characters copied from the portal.
Example fix
// before
// PERPLEXITY_API_KEY is unset -> constructor throws
const llm = new PerplexityLLM(embedder, "llama-3-sonar-large-32k-online");
// after
// server/.env
// PERPLEXITY_API_KEY=pplx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
process.env.PERPLEXITY_API_KEY ??= require("fs").readFileSync("/run/secrets/perplexity_key", "utf8").trim();
const llm = new PerplexityLLM(embedder, "llama-3-sonar-large-32k-online"); Defensive patterns
Strategy: validation
Validate before calling
function assertPerplexityKey() {
if (!process.env.PERPLEXITY_API_KEY || !process.env.PERPLEXITY_API_KEY.trim()) {
throw new Error("PERPLEXITY_API_KEY is missing — get one at https://www.perplexity.ai/settings/api");
}
}
// run before constructing PerplexityLLM
assertPerplexityKey();
const llm = new PerplexityLLM(embedder, modelPref); Type guard
function hasPerplexityKey(env = process.env) {
return typeof env.PERPLEXITY_API_KEY === "string" && env.PERPLEXITY_API_KEY.trim().length > 0;
} Try / catch
let llm;
try {
llm = new PerplexityLLM(embedder, modelPref);
} catch (e) {
if (/No Perplexity API key/i.test(e.message)) {
return { ok: false, reason: "missing-api-key", action: "configure PERPLEXITY_API_KEY" };
}
throw e;
} Prevention
- Centralise env validation at server boot and fail with a single, actionable message listing every missing provider key.
- Keep a .env.example with the exact variable names (PERPLEXITY_API_KEY) commented out so typos are caught early.
- After rotating keys, always recreate/restart the process so the new env is loaded.
- Use a secret manager rather than editing .env by hand to avoid whitespace/quote artifacts.
When it happens
Trigger: Instantiating `new PerplexityLLM(embedder, modelPreference)` while PERPLEXITY_API_KEY is unset, empty string, or whitespace-trimmed to nothing. This includes selecting Perplexity as the workspace LLM in the UI before the key is configured, or running the server with a .env that omits the variable.
Common situations: Fresh clone of AnythingLLM where the developer copied .env.example but never filled in PERPLEXITY_API_KEY; a deployment where the env var is set in one process (e.g. shell) but not exported into the Node process; a typo'd key name (PERPLEXITY_KEY vs PERPLEXITY_API_KEY); rotating a revoked key and forgetting to update the running container.
Related errors
- No PPIO API key was set.
- No SambaNova API key was set.
- No TogetherAI API key was set.
- No Minimax API key was set.
- No Mistral API key was set.
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/ace19a1ad2b7e728.
Report an issue: GitHub.