Mintplex-Labs/anything-llm · critical · Error

No Cohere API key was set.

Error message

No Cohere API key was set.

What it means

Thrown by the CohereLLM constructor when process.env.COHERE_API_KEY is falsy. AnythingLLM uses Cohere's OpenAI-compatible endpoint (https://api.cohere.ai/compatibility/v1) via the OpenAI SDK, which still requires the Cohere API key as apiKey. The guard fails fast so no call ever goes out unauthenticated.

Source

Thrown at server/utils/AiProviders/cohere/index.js:14

const { NativeEmbedder } = require("../../EmbeddingEngines/native");
const { MODEL_MAP } = require("../modelMap");
const {
  LLMPerformanceMonitor,
} = require("../../helpers/chat/LLMPerformanceMonitor");
const {
  handleDefaultStreamResponseV2,
} = require("../../helpers/chat/responses");

class CohereLLM {
  constructor(embedder = null, modelPreference = null) {
    const { OpenAI: OpenAIApi } = require("openai");
    if (!process.env.COHERE_API_KEY)
      throw new Error("No Cohere API key was set.");
    this.className = "CohereLLM";

    // Cohere exposes an OpenAI-compatible API which lets us reuse the OpenAI SDK
    // across the app instead of the cohere-ai package. https://docs.cohere.com/docs/compatibility-api
    this.openai = new OpenAIApi({
      baseURL: "https://api.cohere.ai/compatibility/v1",
      apiKey: process.env.COHERE_API_KEY,
    });
    this.model = modelPreference || process.env.COHERE_MODEL_PREF;
    this.limits = {
      history: this.promptWindowLimit() * 0.15,
      system: this.promptWindowLimit() * 0.15,
      user: this.promptWindowLimit() * 0.7,
    };

    this.embedder = embedder ?? new NativeEmbedder();
    this.defaultTemp = 0.7;
    this.#log(

View on GitHub (pinned to 526360e320)

Solutions

  1. Set `COHERE_API_KEY=<your cohere key>` in .env and restart the server.
  2. Re-save the Cohere provider credentials in the UI to persist the key.
  3. Optionally set COHERE_MODEL_PREF to a specific model; otherwise this.model stays undefined and later calls may need it.
  4. Verify with `printenv COHERE_API_KEY` in the running environment.

Example fix

// before
// .env
COHERE_API_KEY=

// after
// .env
COHERE_API_KEY=<cohere-key>
COHERE_MODEL_PREF=command-r-plus
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.COHERE_API_KEY) {
  throw new Error(
    "COHERE_API_KEY is missing. Generate one in the Cohere dashboard before selecting this provider."
  );
}
const llm = new CohereLLM(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 CohereLLM(embedder, modelPref);
} catch (e) {
  if (/No Cohere API key/.test(e.message)) {
    return { ok: false, reason: "missing-cohere-key" };
  }
  throw e;
}

Prevention

When it happens

Trigger: Constructing CohereLLM with COHERE_API_KEY unset. The constructor then sets className, builds the OpenAI client against the compatibility baseURL, and resolves this.model from COHERE_MODEL_PREF — all blocked by the guard.

Common situations: Cohere provider selected but key not entered; key stored under COHERE_KEY; .env updated but server not restarted; trial key expired and removed.

Related errors


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