{"record":{"id":"7bd2cb46e58313f5","repo":"Mintplex-Labs/anything-llm","slug":"no-groq-api-key-was-set","errorCode":null,"errorMessage":"No Groq API key was set.","messagePattern":"No Groq API key was set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/groq/index.js","lineNumber":13,"sourceCode":"const { NativeEmbedder } = require(\"../../EmbeddingEngines/native\");\nconst {\n  LLMPerformanceMonitor,\n} = require(\"../../helpers/chat/LLMPerformanceMonitor\");\nconst {\n  handleDefaultStreamResponseV2,\n} = require(\"../../helpers/chat/responses\");\nconst { MODEL_MAP } = require(\"../modelMap\");\n\nclass GroqLLM {\n  constructor(embedder = null, modelPreference = null) {\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    if (!process.env.GROQ_API_KEY) throw new Error(\"No Groq API key was set.\");\n    this.className = \"GroqLLM\";\n\n    this.openai = new OpenAIApi({\n      baseURL: \"https://api.groq.com/openai/v1\",\n      apiKey: process.env.GROQ_API_KEY,\n    });\n    this.model =\n      modelPreference || process.env.GROQ_MODEL_PREF || \"llama-3.1-8b-instant\";\n    this.limits = {\n      history: this.promptWindowLimit() * 0.15,\n      system: this.promptWindowLimit() * 0.15,\n      user: this.promptWindowLimit() * 0.7,\n    };\n\n    this.embedder = embedder ?? new NativeEmbedder();\n    this.defaultTemp = 0.7;\n  }\n","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/utils/AiProviders/groq/index.js#L1-L31","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add GROQ_API_KEY=<your gsk_... key> to the backend .env file (server root, same scope as STORAGE_DIR etc.), not the frontend.","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.","Fully restart the server process (env changes are read only at boot); for Docker: docker compose down && up.","Verify inside the running context: docker exec <container> printenv GROQ_API_KEY or console.log(process.env.GROQ_API_KEY) on the server.","Get/rotate a valid key at console.groq.com/keys if the variable exists but auth still fails downstream."],"exampleFix":"// before (.env)\nGROQ_MODEL_PREF=llama-3.1-8b-instant\n\n// after (.env)\nGROQ_API_KEY=gsk_abc123...\nGROQ_MODEL_PREF=llama-3.1-8b-instant","handlingStrategy":"validation","validationCode":"function assertGroqConfig() {\n  if (!process.env.GROQ_API_KEY) {\n    throw new Error(\"GROQ_API_KEY is missing — set it in the server .env and restart.\");\n  }\n}\n// run before constructing/selecting the provider\nassertGroqConfig();\nconst llm = new GroqLLM(embedder, modelPref);","typeGuard":null,"tryCatchPattern":"try {\n  const llm = new GroqLLM(embedder, modelPref);\n} catch (e) {\n  if (/Groq API key/i.test(e.message)) return setupError(e); // config UX, not a crash\n  throw e;\n}","preventionTips":["Keep a required-env checklist per provider and validate all vars at server boot, not lazily on first chat.","In Docker, define GROQ_API_KEY under environment: (or --env-file) and recreate the container after changes.","Never rely on the settings UI to satisfy constructor-time env checks — this provider only reads process.env.","Smoke-test config after deploy: node -e \"console.log(!!process.env.GROQ_API_KEY)\" in the server context."],"tags":["groq","anythingllm","configuration","env-var","api-key","constructor"],"backgroundTag":"missing-api-key","analyzedSha":"f92433b4ea0598492a1e6645ea22addbb4dd1287","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}