{"record":{"id":"ce05419342142a94","repo":"mem0ai/mem0","slug":"deepseek-api-key-is-required","errorCode":null,"errorMessage":"DeepSeek API key is required","messagePattern":"DeepSeek API key is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/llms/deepseek.ts","lineNumber":9,"sourceCode":"import { OpenAILLM } from \"./openai\";\nimport { LLMConfig, Message } from \"../types\";\nimport { LLMResponse } from \"./base\";\n\nexport class DeepSeekLLM extends OpenAILLM {\n  constructor(config: LLMConfig) {\n    const apiKey = config.apiKey || process.env.DEEPSEEK_API_KEY;\n    if (!apiKey) {\n      throw new Error(\"DeepSeek API key is required\");\n    }\n    super({\n      ...config,\n      apiKey,\n      baseURL:\n        config.baseURL ||\n        process.env.DEEPSEEK_API_BASE ||\n        \"https://api.deepseek.com\",\n      model: config.model || \"deepseek-chat\",\n    });\n  }\n\n  async generateResponse(\n    messages: Message[],\n    responseFormat?: { type: string },\n    tools?: any[],\n  ): Promise<string | LLMResponse> {\n    try {","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/llms/deepseek.ts#L1-L27","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst mem = new Memory({ llm: { provider: 'deepseek', config: {} } });\n// throws: DeepSeek API key is required (DEEPSEEK_API_KEY not set)\n\n// after\nimport 'dotenv/config';\nconst mem = new Memory({\n  llm: {\n    provider: 'deepseek',\n    config: { apiKey: process.env.DEEPSEEK_API_KEY },\n  },\n});","handlingStrategy":"validation","validationCode":"function resolveDeepSeekKey(cfg: LLMConfig): string {\n  const key = cfg.apiKey ?? process.env.DEEPSEEK_API_KEY;\n  if (!key) throw new Error('Set config.apiKey or export DEEPSEEK_API_KEY before constructing Memory');\n  return key;\n}","typeGuard":"const hasDeepSeekKey = (cfg: LLMConfig): boolean => Boolean(cfg.apiKey || process.env.DEEPSEEK_API_KEY);","tryCatchPattern":"try {\n  new DeepSeekLLM(config);\n} catch (err) {\n  if ((err as Error).message === 'DeepSeek API key is required') {\n    failStartup('DEEPSEEK_API_KEY missing — refusing to boot');\n  }\n  throw err;\n}","preventionTips":["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."],"tags":["deepseek","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"}