Mintplex-Labs/anything-llm · critical · Error

No Cerebras API key was set.

Error message

No Cerebras API key was set.

What it means

Thrown by the CerebrasLLM constructor when process.env.CEREBRAS_API_KEY is falsy. The provider builds an OpenAI-compatible client against https://api.cerebras.ai/v1 with this key, so it is mandatory before any chat/stream call.

Source

Thrown at server/utils/AiProviders/cerebras/index.js:16

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

class CerebrasLLM {
  static modelContextWindows = {};

  constructor(embedder = null, modelPreference = null) {
    const { OpenAI: OpenAIApi } = require("openai");
    if (!process.env.CEREBRAS_API_KEY)
      throw new Error("No Cerebras API key was set.");

    this.className = "CerebrasLLM";
    this.openai = new OpenAIApi({
      baseURL: "https://api.cerebras.ai/v1",
      apiKey: process.env.CEREBRAS_API_KEY,
    });
    this.model =
      modelPreference || process.env.CEREBRAS_MODEL_PREF || "gpt-oss-120b";
    // Lazy load the limits to avoid blocking the main thread on cacheContextWindows
    this.limits = null;

    this.embedder = embedder ?? new NativeEmbedder();
    this.defaultTemp = 0;

    CerebrasLLM.cacheContextWindows(true);
    this.#log(`Initialized with model: ${this.model}`);
  }

View on GitHub (pinned to 526360e320)

Solutions

  1. Set `CEREBRAS_API_KEY=<your cerebras key>` in .env and restart the server.
  2. Re-save the Cerebras provider credentials in the UI to persist the key.
  3. Verify with `printenv CEREBRAS_API_KEY` in the server environment.
  4. Optionally set CEREBRAS_MODEL_PREF to override the default gpt-oss-120b.

Example fix

// before
// .env
CEREBRAS_API_KEY=

// after
// .env
CEREBRAS_API_KEY=csk-xxxxxxxxxxxxxxxx
CEREBRAS_MODEL_PREF=gpt-oss-120b
Defensive patterns

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: Constructing CerebrasLLM with CEREBRAS_API_KEY unset. The constructor also sets up the model preference (default gpt-oss-120b) and lazy-loads limits, but the key guard short-circuits all of that.

Common situations: Cerebras provider selected but key not entered; key env var misnamed (e.g. CEREBRAS_KEY); .env updated but process not restarted; deploying without the env.

Related errors


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