{"record":{"id":"94b80010b66e9459","repo":"mem0ai/mem0","slug":"groq-api-key-is-required","errorCode":null,"errorMessage":"Groq API key is required","messagePattern":"Groq API key is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/llms/groq.ts","lineNumber":14,"sourceCode":"import type { Groq } from \"groq-sdk\";\nimport { LLM, LLMResponse } from \"./base\";\nimport { LLMConfig, Message } from \"../types\";\nimport { loadPeer } from \"../utils/load_peer\";\n\nexport class GroqLLM implements LLM {\n  private client!: Groq;\n  private model: string;\n  private readonly apiKey: string;\n\n  constructor(config: LLMConfig) {\n    const apiKey = config.apiKey || process.env.GROQ_API_KEY;\n    if (!apiKey) {\n      throw new Error(\"Groq API key is required\");\n    }\n    this.apiKey = apiKey;\n    this.model = config.model || \"llama3-70b-8192\";\n  }\n\n  private async ensureClient(): Promise<void> {\n    if (this.client) return;\n    const sdk = await loadPeer(\n      \"groq-sdk\",\n      \"Groq LLM\",\n      () => import(\"groq-sdk\"),\n    );\n    this.client = new sdk.Groq({ apiKey: this.apiKey });\n  }\n\n  async generateResponse(\n    messages: Message[],\n    responseFormat?: { type: string },","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/llms/groq.ts#L1-L32","documentation":"Thrown synchronously by the GroqLLM constructor when no Groq API key is found. The provider checks config.apiKey, then the GROQ_API_KEY environment variable, and throws when both are missing. The Groq SDK client is created lazily (ensureClient), so key validation happens up front at construction.","triggerScenarios":"Instantiating GroqLLM (provider 'groq') with config.apiKey unset and GROQ_API_KEY absent from the process environment. Note the constructor reads no other fallback, so a key stored only in a platform's secret store that was never exported will not be seen.","commonSituations":"New Groq signup that has not created an API key at console.groq.com/keys; env var set in a different shell than the one running the app; .env loaded after construction; CI pipelines missing the GROQ_API_KEY secret.","solutions":["Create a key at console.groq.com/keys and export it: export GROQ_API_KEY=gsk_...","Or pass it directly: llm: { provider: 'groq', config: { apiKey: process.env.GROQ_API_KEY } }.","Load dotenv before constructing Memory if the key lives in a local .env file.","Add GROQ_API_KEY to your CI/deployment secret configuration."],"exampleFix":"// before\nconst mem = new Memory({ llm: { provider: 'groq', config: { model: 'llama3-70b-8192' } } });\n// throws: Groq API key is required\n\n// after\nconst mem = new Memory({\n  llm: {\n    provider: 'groq',\n    config: {\n      apiKey: process.env.GROQ_API_KEY!,\n      model: 'llama-3.3-70b-versatile',\n    },\n  },\n});","handlingStrategy":"validation","validationCode":"function assertGroqKey(cfg: LLMConfig) {\n  if (!cfg.apiKey && !process.env.GROQ_API_KEY) {\n    throw new Error('GROQ_API_KEY not configured — get one at console.groq.com/keys');\n  }\n}","typeGuard":"const hasGroqKey = (cfg: LLMConfig): boolean => Boolean(cfg.apiKey || process.env.GROQ_API_KEY);","tryCatchPattern":"try { new GroqLLM(config); } catch (e) {\n  if ((e as Error).message === 'Groq API key is required') throw new StartupConfigError('missing GROQ_API_KEY');\n  throw e;\n}","preventionTips":["Add a boot-time env schema check (e.g. zod) listing GROQ_API_KEY as required when provider is 'groq'.","Load dotenv before constructing Memory.","Groq keys are free but per-organization — document where yours lives."],"tags":["groq","llm","api-key","config","env","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}