Mintplex-Labs/anything-llm · critical · Error

No CometAPI API key was set.

Error message

No CometAPI API key was set.

What it means

Constructor guard that prevents CometApiLLM instantiation when COMETAPI_LLM_API_KEY is absent from the environment. Because the key is required to build the OpenAI-compatible client (baseURL https://api.cometapi.com/v1), the class cannot function without it, so construction fails fast.

Source

Thrown at server/utils/AiProviders/cometapi/index.js:25

} = require("../../helpers/chat/responses");
const fs = require("fs");
const path = require("path");
const { safeJsonParse } = require("../../http");
const {
  LLMPerformanceMonitor,
} = require("../../helpers/chat/LLMPerformanceMonitor");
const { COMETAPI_IGNORE_PATTERNS } = require("./constants");
const cacheFolder = path.resolve(
  process.env.STORAGE_DIR
    ? path.resolve(process.env.STORAGE_DIR, "models", "cometapi")
    : path.resolve(__dirname, `../../../storage/models/cometapi`)
);

class CometApiLLM {
  defaultTimeout = 3_000;
  constructor(embedder = null, modelPreference = null) {
    if (!process.env.COMETAPI_LLM_API_KEY)
      throw new Error("No CometAPI API key was set.");

    this.className = "CometApiLLM";
    const { OpenAI: OpenAIApi } = require("openai");
    this.basePath = "https://api.cometapi.com/v1";
    this.openai = new OpenAIApi({
      baseURL: this.basePath,
      apiKey: process.env.COMETAPI_LLM_API_KEY ?? null,
      defaultHeaders: {
        "HTTP-Referer": "https://anythingllm.com",
        "X-CometAPI-Source": "anythingllm",
      },
    });
    this.model =
      modelPreference || process.env.COMETAPI_LLM_MODEL_PREF || "gpt-5-mini";
    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 COMETAPI_LLM_API_KEY in the .env file (or system environment) to a valid key from the CometAPI dashboard.
  2. Restart the server process after updating .env so the new env var is loaded.
  3. In the AnythingLLM UI, re-enter the API key in the CometAPI provider settings and save.

Example fix

# .env
COMETAPI_LLM_API_KEY=sk-your-cometapi-key-here
Defensive patterns

Strategy: validation

Validate before calling

const COMETAPI_KEY = process.env.COMETAPI_LLM_API_KEY;
if (!COMETAPI_KEY || COMETAPI_KEY.trim() === '')
  throw new Error('COMETAPI_LLM_API_KEY must be set before using the CometAPI provider');

Try / catch

// Wrap provider instantiation so a missing key does not crash the app
try {
  provider = new CometApiLLM(embedder, modelPref);
} catch (e) {
  if (/No CometAPI API key/i.test(e.message))
    return respondConfigError('Set COMETAPI_LLM_API_KEY in the CometAPI provider settings.');
  throw e;
}

Prevention

When it happens

Trigger: Instantiating `new CometApiLLM()` (typically via the provider factory) when COMETAPI_LLM_API_KEY is unset, empty string, or whitespace; selecting CometAPI as the LLM provider in AnythingLLM settings without having saved an API key.

Common situations: Fresh deployment where the CometAPI provider was selected but the key field was left blank; .env file missing the key after a config migration; CI/test environment that does not inject the key; copying env.example to .env but forgetting to fill in the CometAPI line.

Related errors


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