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
- Set `CEREBRAS_API_KEY=<your cerebras key>` in .env and restart the server.
- Re-save the Cerebras provider credentials in the UI to persist the key.
- Verify with `printenv CEREBRAS_API_KEY` in the server environment.
- 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
- Validate CEREBRAS_API_KEY at provider-save time and mark the provider unready until set.
- Use the exact env var name from a shared constants file.
- Restart after credential edits.
- Optionally pre-validate the key with a /v1/models call before marking the provider active.
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
- No Anthropic API key was set.
- No ApiPie LLM API key was set.
- No Azure API key was set.
- AWS_BEDROCK_LLM_API_KEY is required for AWS Bedrock.
- No Cohere API key was set.
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/e27ccb6843576b3f.
Report an issue: GitHub.