{"record":{"id":"7832427725b8efb2","repo":"mem0ai/mem0","slug":"authentication-required","errorCode":null,"errorMessage":"Authentication required.","messagePattern":"Authentication required\\.","errorType":"http","errorClass":"HTTPException","httpStatus":401,"severity":"error","filePath":"server/auth.py","lineNumber":189,"sourceCode":"    raise HTTPException(\n        status_code=401,\n        detail=\"Authentication required. Provide a Bearer token or X-API-Key header.\",\n        headers={\"WWW-Authenticate\": \"Bearer\"},\n    )\n\n\nasync def require_auth(\n    request: Request,\n    user: User | None = Depends(verify_auth),\n) -> User:\n    \"\"\"Like verify_auth but guarantees a non-None User. Use for endpoints that require auth.\"\"\"\n    if user is None:\n        if getattr(request.state, \"auth_type\", \"none\") in {\"admin_api_key\", \"disabled\"}:\n            with SessionLocal() as db:\n                default_user = _get_default_user(db)\n            if default_user is not None:\n                return default_user\n        raise HTTPException(status_code=401, detail=\"Authentication required.\")\n    return user\n\n\n_BOOTSTRAP_ADMIN = User(\n    id=uuid.UUID(int=0), name=\"admin_api_key\", email=\"\", password_hash=\"\", role=\"admin\", created_at=datetime.min.replace(tzinfo=timezone.utc),\n)\n\n\nasync def require_admin(\n    request: Request,\n    user: User | None = Depends(verify_auth),\n) -> User:\n    \"\"\"Like require_auth but also enforces admin role.\n\n    ADMIN_API_KEY and AUTH_DISABLED callers are treated as admin even when\n    the users table is empty (fresh-deploy bootstrap).\n    \"\"\"\n    auth_type = getattr(request.state, \"auth_type\", \"none\")","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/server/auth.py#L171-L207","documentation":"Error \"Authentication required.\" thrown in mem0ai/mem0.","triggerScenarios":"Thrown at server/auth.py:189 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Authenticate first (login or API key) before calling this endpoint."],"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"}