mem0ai/mem0 · error · Error
DeepSeek API key is required
Error message
DeepSeek API key is required
What it means
Thrown synchronously by the DeepSeekLLM constructor when no API key can be resolved. The provider tries config.apiKey first, then the DEEPSEEK_API_KEY environment variable, and throws only when both are absent. This is a fail-fast guard before the underlying OpenAI-compatible client is built.
Source
Thrown at mem0-ts/src/oss/src/llms/deepseek.ts:9
import { OpenAILLM } from "./openai";
import { LLMConfig, Message } from "../types";
import { LLMResponse } from "./base";
export class DeepSeekLLM extends OpenAILLM {
constructor(config: LLMConfig) {
const apiKey = config.apiKey || process.env.DEEPSEEK_API_KEY;
if (!apiKey) {
throw new Error("DeepSeek API key is required");
}
super({
...config,
apiKey,
baseURL:
config.baseURL ||
process.env.DEEPSEEK_API_BASE ||
"https://api.deepseek.com",
model: config.model || "deepseek-chat",
});
}
async generateResponse(
messages: Message[],
responseFormat?: { type: string },
tools?: any[],
): Promise<string | LLMResponse> {
try {View on GitHub (pinned to 001c235229)
Solutions
- Set the env var: export DEEPSEEK_API_KEY=sk-... (or add it to your platform's environment settings).
- Or pass it explicitly in the config: llm: { provider: 'deepseek', config: { apiKey: process.env.DEEPSEEK_API_KEY } }.
- If using dotenv, ensure import 'dotenv/config' (or config()) executes before the Memory instance is created — the constructor reads process.env at construction time.
- Never commit the key; use a secrets manager in deployed environments.
Example fix
// before
const mem = new Memory({ llm: { provider: 'deepseek', config: {} } });
// throws: DeepSeek API key is required (DEEPSEEK_API_KEY not set)
// after
import 'dotenv/config';
const mem = new Memory({
llm: {
provider: 'deepseek',
config: { apiKey: process.env.DEEPSEEK_API_KEY },
},
}); Defensive patterns
Strategy: validation
Validate before calling
function resolveDeepSeekKey(cfg: LLMConfig): string {
const key = cfg.apiKey ?? process.env.DEEPSEEK_API_KEY;
if (!key) throw new Error('Set config.apiKey or export DEEPSEEK_API_KEY before constructing Memory');
return key;
} Type guard
const hasDeepSeekKey = (cfg: LLMConfig): boolean => Boolean(cfg.apiKey || process.env.DEEPSEEK_API_KEY);
Try / catch
try {
new DeepSeekLLM(config);
} catch (err) {
if ((err as Error).message === 'DeepSeek API key is required') {
failStartup('DEEPSEEK_API_KEY missing — refusing to boot');
}
throw err;
} Prevention
- Import dotenv/config as the first statement of the entry file.
- Fail fast at boot when required env vars are absent rather than at first request.
- Store DEEPSEEK_API_KEY in the platform secret manager for deployments.
When it happens
Trigger: Creating DeepSeekLLM (provider 'deepseek') with config.apiKey undefined/empty AND process.env.DEEPSEEK_API_KEY unset (or not visible to the process). Common in serverless/CI where .env files are not loaded into the runtime environment.
Common situations: Forgetting to export DEEPSEEK_API_KEY in the shell before starting the process; .env file present but the dotenv loader runs after Memory is constructed; deploying to Vercel/Lambda where env vars must be configured in the platform, not a local file; passing apiKey under the wrong config key name.
Related errors
- Groq 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/ce05419342142a94.
Report an issue: GitHub.