{"record":{"id":"70a1eb6e4712964e","repo":"mem0ai/mem0","slug":"authentication-failed-your-api-key-may-be-invalid-70a1eb","errorCode":null,"errorMessage":"Authentication failed. Your API key may be invalid or expired.","messagePattern":"Authentication failed\\. Your API key may be invalid or expired\\.","errorType":"http","errorClass":"AuthError","httpStatus":401,"severity":"error","filePath":"cli/python/src/mem0_cli/backend/platform.py","lineNumber":43,"sourceCode":"        self._client = httpx.Client(\n            base_url=self.base_url,\n            headers={\n                \"Authorization\": f\"Token {config.api_key}\",\n                \"Content-Type\": \"application/json\",\n                \"X-Mem0-Source\": \"cli\",\n                \"X-Mem0-Client-Language\": \"python\",\n                \"X-Mem0-Client-Version\": __version__,\n            },\n            timeout=30.0,\n        )\n\n    def _request(self, method: str, path: str, **kwargs: Any) -> Any:\n        from mem0_cli.state import capture_notice, is_agent_mode\n\n        self._client.headers[\"X-Mem0-Caller-Type\"] = \"agent\" if is_agent_mode() else \"user\"\n        resp = self._client.request(method, path, **kwargs)\n        if resp.status_code == 401:\n            raise AuthError(\"Authentication failed. Your API key may be invalid or expired.\")\n        if resp.status_code == 404:\n            raise NotFoundError(f\"Resource not found: {path}\")\n        if resp.status_code == 400:\n            # Extract API error detail when available\n            try:\n                detail = resp.json().get(\"detail\", resp.text)\n            except Exception:\n                detail = resp.text\n            raise APIError(f\"Bad request to {path}: {detail}\")\n        resp.raise_for_status()\n        if resp.status_code == 204:\n            return {}\n        data = resp.json()\n\n        # Pull the unclaimed-Agent-Mode notice out of the body (or the header\n        # fallback for endpoints that return non-dict / non-dict-leading\n        # payloads) and stash it for end-of-command surfacing.\n        notice = None","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/cli/python/src/mem0_cli/backend/platform.py#L25-L61","documentation":"Error \"Authentication failed. Your API key may be invalid or expired.\" thrown in mem0ai/mem0.","triggerScenarios":"Thrown at cli/python/src/mem0_cli/backend/platform.py:43 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify your Mem0 API key is correct and not expired; regenerate it in the Mem0 dashboard if needed.","Check that the MEM0_API_KEY environment variable is set and passed to the client."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}