Mintplex-Labs/anything-llm · critical · Error

No ApiPie LLM API key was set.

Error message

No ApiPie LLM API key was set.

What it means

Thrown by the ApiPieLLM constructor when process.env.APIPIE_LLM_API_KEY is falsy. ApiPie is an OpenAI-compatible aggregator, so an API key is mandatory before any chat completion or stream call. Like other provider constructors, it fails fast so downstream code never runs without credentials.

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 526360e320)

Solutions

  1. Set `APIPIE_LLM_API_KEY=<your apipie key>` in .env and restart the server.
  2. Re-save the ApiPie provider credentials via the UI so AnythingLLM persists them to .env.
  3. Confirm the env is visible to the process: `printenv APIPIE_LLM_API_KEY` in the same context the server runs.
  4. Optionally also set APIPIE_LLM_MODEL_PREF to avoid the default `openrouter/mistral-7b-instruct` fallback.

Example fix

// before
// .env
APIPIE_LLM_API_KEY=

// after
// .env
APIPIE_LLM_API_KEY=apipie-xxxxxxxxxxxxxxxx
APIPIE_LLM_MODEL_PREF=openrouter/mistral-7b-instruct
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.APIPIE_LLM_API_KEY) {
  throw new Error(
    "APIPIE_LLM_API_KEY is missing. Set it before selecting the ApiPie provider."
  );
}
const llm = new ApiPieLLM(embedder, modelPref);

Type guard

/** @param {unknown} v @returns {boolean} */
function isNonEmptyKey(v) {
  return typeof v === "string" && v.trim().length > 0;
}

Try / catch

try {
  const llm = new ApiPieLLM(embedder, modelPref);
} catch (e) {
  if (/No ApiPie LLM API key/.test(e.message)) {
    return { ok: false, reason: "missing-api-key" };
  }
  throw e;
}

Prevention

When it happens

Trigger: Selecting the ApiPie provider and triggering a chat/embed while APIPIE_LLM_API_KEY is unset. The constructor reads the key directly from process.env and also applies a `?? null` fallback when building the OpenAI client, but the guard above already aborts construction first.

Common situations: ApiPie account not yet created / key not copied into .env; key stored under a differently-named variable; multi-instance deploy where only one node has the env; .env updated but process not restarted.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/590e53aa1d7c7b3e. Report an issue: GitHub.