mem0ai/mem0 · error · Error
Groq API key is required
Error message
Groq API key is required
What it means
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.
Source
Thrown at mem0-ts/src/oss/src/llms/groq.ts:14
import type { Groq } from "groq-sdk";
import { LLM, LLMResponse } from "./base";
import { LLMConfig, Message } from "../types";
import { loadPeer } from "../utils/load_peer";
export class GroqLLM implements LLM {
private client!: Groq;
private model: string;
private readonly apiKey: string;
constructor(config: LLMConfig) {
const apiKey = config.apiKey || process.env.GROQ_API_KEY;
if (!apiKey) {
throw new Error("Groq API key is required");
}
this.apiKey = apiKey;
this.model = config.model || "llama3-70b-8192";
}
private async ensureClient(): Promise<void> {
if (this.client) return;
const sdk = await loadPeer(
"groq-sdk",
"Groq LLM",
() => import("groq-sdk"),
);
this.client = new sdk.Groq({ apiKey: this.apiKey });
}
async generateResponse(
messages: Message[],
responseFormat?: { type: string },View on GitHub (pinned to 001c235229)
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.
Example fix
// before
const mem = new Memory({ llm: { provider: 'groq', config: { model: 'llama3-70b-8192' } } });
// throws: Groq API key is required
// after
const mem = new Memory({
llm: {
provider: 'groq',
config: {
apiKey: process.env.GROQ_API_KEY!,
model: 'llama-3.3-70b-versatile',
},
},
}); Defensive patterns
Strategy: validation
Validate before calling
function assertGroqKey(cfg: LLMConfig) {
if (!cfg.apiKey && !process.env.GROQ_API_KEY) {
throw new Error('GROQ_API_KEY not configured — get one at console.groq.com/keys');
}
} Type guard
const hasGroqKey = (cfg: LLMConfig): boolean => Boolean(cfg.apiKey || process.env.GROQ_API_KEY);
Try / catch
try { new GroqLLM(config); } catch (e) {
if ((e as Error).message === 'Groq API key is required') throw new StartupConfigError('missing GROQ_API_KEY');
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- DeepSeek API key is required
- MiniMax API key is required
- Sarvam API key is required
- Together API key is required
- Mistral API key is required
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/94b80010b66e9459.
Report an issue: GitHub.