{"record":{"id":"833414bf94aa5bfa","repo":"mem0ai/mem0","slug":"deepseek-llm-failed-message","errorCode":null,"errorMessage":"DeepSeek LLM failed: ${message}","messagePattern":"DeepSeek LLM failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/llms/deepseek.ts","lineNumber":31,"sourceCode":"      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 {\n      return await super.generateResponse(messages, responseFormat, tools);\n    } catch (err) {\n      const message = err instanceof Error ? err.message : String(err);\n      throw new Error(`DeepSeek LLM failed: ${message}`);\n    }\n  }\n\n  async generateChat(messages: Message[]): Promise<LLMResponse> {\n    try {\n      return await super.generateChat(messages);\n    } catch (err) {\n      const message = err instanceof Error ? err.message : String(err);\n      throw new Error(`DeepSeek LLM failed: ${message}`);\n    }\n  }\n}\n","sourceCodeStart":13,"sourceCodeEnd":44,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/llms/deepseek.ts#L13-L44","documentation":"Thrown by DeepSeekLLM.generateResponse when the inherited OpenAILLM call to DeepSeek's OpenAI-compatible API fails for any reason. The wrapper preserves the original error text after the 'DeepSeek LLM failed:' prefix, so the suffix identifies whether it was auth (401), rate limit (429), model issues, JSON mode problems, or network.","triggerScenarios":"Calling generateResponse() on DeepSeekLLM (directly or via Memory.add/search/ update flows) when DeepSeek returns 401 invalid key, 402 insufficient balance, 429 rate limit, an invalid model name, a malformed responseFormat for JSON mode, or when the network call to https://api.deepseek.com fails or times out.","commonSituations":"Expired or revoked DeepSeek key; DeepSeek account out of credits (402 is common on the free-trial exhaustion); switching model between deepseek-chat and deepseek-reasoner with parameters only one supports; concurrent requests exceeding the per-key rate limit; custom DEEPSEEK_API_BASE pointing at a proxy that returns HTML errors.","solutions":["Inspect the message after the prefix: 401 → fix the key, 402 → top up balance, 429 → back off, model errors → correct the model string.","Verify the key works outside mem0: curl https://api.deepseek.com/models with Authorization: Bearer $DEEPSEEK_API_KEY.","For 429s, wrap calls in exponential-backoff retry (DeepSeek rate limits are per-minute TPM/RPM).","If using a custom baseURL, confirm the proxy is reachable and OpenAI-compatible from the runtime environment.","Confirm the model value: defaults to deepseek-chat; deepseek-reasoner rejects some parameters (e.g. temperature)."],"exampleFix":"// before\nconst res = await deepSeekLlm.generateResponse(messages, { type: 'json_object' });\n// DeepSeek LLM failed: 402 Insufficient Balance\n\n// after (fail fast on balance/auth, retry on transient 429)\ntry {\n  const res = await deepSeekLlm.generateResponse(messages, { type: 'json_object' });\n} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e);\n  if (msg.includes('402') || msg.includes('401')) throw e; // fatal: billing/auth\n  if (msg.includes('429')) await backoffThenRetry(() => deepSeekLlm.generateResponse(messages));\n  else throw e;\n}","handlingStrategy":"retry","validationCode":"async function deepSeekReachable(base = 'https://api.deepseek.com') {\n  const r = await fetch(`${base}/models`, { headers: { Authorization: `Bearer ${process.env.DEEPSEEK_API_KEY}` } });\n  if (r.status === 401) throw new Error('DeepSeek key invalid');\n  if (r.status === 402) throw new Error('DeepSeek balance exhausted');\n  return r.ok;\n}","typeGuard":"function isDeepSeekFatal(err: unknown): boolean {\n  const m = err instanceof Error ? err.message : String(err);\n  return m.startsWith('DeepSeek LLM failed:') && /401|402|invalid/i.test(m);\n}","tryCatchPattern":"try {\n  return await deepSeekLlm.generateResponse(messages, responseFormat);\n} catch (err) {\n  const msg = String(err);\n  if (/429|timeout|ECONN/i.test(msg)) return retry(fn, { retries: 3 });\n  throw err; // 401/402/model errors are fatal\n}","preventionTips":["Monitor DeepSeek credit balance; 402 surfaces as this wrapped error.","Pin the model you validated (deepseek-chat vs deepseek-reasoner) and its supported params.","Add circuit-breaking around memory.add loops that fan out many LLM calls."],"tags":["deepseek","llm","network","rate-limit","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}