{"record":{"id":"96791fecff534cc1","repo":"bytedance/deer-flow","slug":"mem0-method-path-resp-status-code-resp","errorCode":null,"errorMessage":"mem0 {method} {path} -> {resp.status_code}: {resp.text[:200]}","messagePattern":"mem0 (.+?) (.+?) -> (.+?): (.+?)","errorType":"exception","errorClass":"Mem0APIError","httpStatus":null,"severity":"error","filePath":"backend/packages/harness/deerflow/agents/memory/backends/mem0/client.py","lineNumber":53,"sourceCode":"        self._http = httpx.Client(\n            base_url=base_url.rstrip(\"/\"),\n            headers={\"Authorization\": f\"Token {api_key}\", \"Accept\": \"application/json\"},\n            timeout=timeout_seconds,\n            transport=transport,\n        )\n\n    def close(self) -> None:\n        self._http.close()\n\n    def _request(self, method: str, path: str, **kwargs: Any) -> dict[str, Any]:\n        try:\n            resp = self._http.request(method, path, **kwargs)\n        except httpx.HTTPError as e:\n            raise Mem0APIError(f\"mem0 request failed: {e}\") from e\n        if resp.status_code == 401:\n            raise Mem0AuthError(\"mem0 authentication failed (check the API key)\")\n        if resp.status_code >= 400:\n            raise Mem0APIError(f\"mem0 {method} {path} -> {resp.status_code}: {resp.text[:200]}\")\n        if not resp.content:\n            return {}\n        try:\n            return resp.json()\n        except json.JSONDecodeError as e:\n            raise Mem0APIError(f\"mem0 {method} {path} returned malformed JSON: {e}\") from e\n\n    def add_memories(\n        self,\n        *,\n        messages: list[dict[str, str]],\n        user_id: str | None = None,\n        agent_id: str | None = None,\n        run_id: str | None = None,\n    ) -> dict[str, Any]:\n        \"\"\"Queue extraction (async server-side; response carries an event_id).\"\"\"\n        body: dict[str, Any] = {\"messages\": messages}\n        if user_id:","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/bytedance/deer-flow/blob/1dd6ba1acb03700589994b0366c5d1c7d05e2eff/backend/packages/harness/deerflow/agents/memory/backends/mem0/client.py#L35-L71","documentation":"Raised as Mem0APIError by Mem0Client._request when the mem0 server returns any HTTP status >= 400 other than 401 (which is mapped to Mem0AuthError). The message includes method, path, status code, and the first 200 characters of the response body, so the server's own error text is the primary diagnostic.","triggerScenarios":"Any Mem0Client call (POST /v1/memories/ for add_memories, search, get_context) returning 400 (malformed payload / bad parameter), 403, 404 (wrong base_url path prefix), 422, or 5xx from the mem0 service. Example: requesting top_k outside the server's accepted range, or pointing base_url at a path the server does not serve.","commonSituations":"base_url including or missing a path segment so requests hit a 404; mem0 platform API changed between versions (self-hosted server older/newer than the client expects); a malformed message payload after upstream schema changes; transient 5xx during mem0 incidents.","solutions":["Read the embedded body text — mem0's error message states the exact rejected field or reason","Fix base_url: it must be the API root (default https://api.mem0.ai); remove stray path suffixes or add the correct one for a self-hosted server","For 4xx: correct the offending parameter (e.g. keep top_k in [1,1000] per local validation, and match the server's own limits)","For 5xx: check the mem0 status page / server logs; transient failures are absorbed by failure_policy (default fail_open read / log_and_drop write) or can be retried"],"exampleFix":"# before (config.yaml)\nmemory:\n  manager_class: mem0\n  backend_config:\n    base_url: https://api.mem0.ai/v1   # path duplicated -> 404 on POST /v1/memories/\n\n# after\nmemory:\n  manager_class: mem0\n  backend_config:\n    base_url: https://api.mem0.ai","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from deerflow.agents.memory.backends.mem0.client import Mem0APIError\n\ntry:\n    resp = client.add_memories(messages=msgs, user_id=u)\nexcept Mem0APIError as e:\n    status = int(str(e).split(\"-> \")[1].split(\":\")[0]) if \"-> \" in str(e) else 0\n    if 500 <= status < 600:\n        time.sleep(2); client.add_memories(messages=msgs, user_id=u)  # transient 5xx: one retry\n    else:\n        raise   # 4xx is a payload/config bug — fix the request, don't retry","preventionTips":["Read the embedded status + body text before changing anything — it names the rejected field or the server-side reason","Keep base_url as the bare API root (https://api.mem0.ai) — path suffixes are the top cause of 404-shaped versions of this error","Pin self-hosted mem0 server versions in lockstep with what this client expects"],"tags":["mem0","memory","http","api-error"],"backgroundTag":null,"analyzedSha":"1dd6ba1acb03700589994b0366c5d1c7d05e2eff","analyzedAt":"2026-08-14T21:20:34.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}