Mintplex-Labs/anything-llm · error · Error

No Groq API key was set.

Error message

No Groq API key was set.

What it means

Thrown by the GroqLLM constructor when the GROQ_API_KEY environment variable is not set in the server's process. AnythingLLM provider classes validate their required configuration eagerly at construction time, so selecting Groq as the LLM provider fails immediately rather than at first inference. The key is passed straight into the OpenAI-compatible client pointed at https://api.groq.com/openai/v1.

Solutions

  1. Add GROQ_API_KEY=<your gsk_... key> to the backend .env file (server root, same scope as STORAGE_DIR etc.), not the frontend.
  2. If running under Docker, ensure the variable is passed (docker run -e GROQ_API_KEY=... or listed under environment: in docker-compose.yml) and recreate the container.
  3. Fully restart the server process (env changes are read only at boot); for Docker: docker compose down && up.
  4. Verify inside the running context: docker exec <container> printenv GROQ_API_KEY or console.log(process.env.GROQ_API_KEY) on the server.
  5. Get/rotate a valid key at console.groq.com/keys if the variable exists but auth still fails downstream.

Example fix

// before (.env)
GROQ_MODEL_PREF=llama-3.1-8b-instant

// after (.env)
GROQ_API_KEY=gsk_abc123...
GROQ_MODEL_PREF=llama-3.1-8b-instant
Defensive patterns

Strategy: validation

Validate before calling

function assertGroqConfig() {
  if (!process.env.GROQ_API_KEY) {
    throw new Error("GROQ_API_KEY is missing — set it in the server .env and restart.");
  }
}
// run before constructing/selecting the provider
assertGroqConfig();
const llm = new GroqLLM(embedder, modelPref);

Try / catch

try {
  const llm = new GroqLLM(embedder, modelPref);
} catch (e) {
  if (/Groq API key/i.test(e.message)) return setupError(e); // config UX, not a crash
  throw e;
}

Prevention

When it happens

Trigger: Instantiating new GroqLLM(embedder, modelPreference) — i.e., picking 'Groq' as the chat provider in workspace or system LLM settings — while process.env.GROQ_API_KEY is undefined. This includes a missing backend .env entry, a docker-compose/Container deployment without the variable passed through, or a process manager (PM2/systemd) started in a shell that lacks the exported variable.

Common situations: Fresh clone without completing .env; setting the key in the frontend settings UI but not in the server environment (this provider only reads process.env); typos like GROQAPI_KEY or GROQ_APIKEY; docker image restarted without --env-file; key deleted during rotation while the container still runs with the old env.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@f92433b4ea (2026-08-18). Data as JSON: /api/errors/7bd2cb46e58313f5. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/AiProviders/groq/index.js:13

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

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

    this.openai = new OpenAIApi({
      baseURL: "https://api.groq.com/openai/v1",
      apiKey: process.env.GROQ_API_KEY,
    });
    this.model =
      modelPreference || process.env.GROQ_MODEL_PREF || "llama-3.1-8b-instant";
    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;
  }

View on GitHub (pinned to f92433b4ea)