{"record":{"id":"f2c3e151c4c4e255","repo":"mem0ai/mem0","slug":"authentication-required-provide-a-bearer-token-or","errorCode":null,"errorMessage":"Authentication required. Provide a Bearer token or X-API-Key header.","messagePattern":"Authentication required\\. Provide a Bearer token or X-API-Key header\\.","errorType":"http","errorClass":"HTTPException","httpStatus":401,"severity":"error","filePath":"server/auth.py","lineNumber":171,"sourceCode":"    \"\"\"\n    if credentials is not None:\n        _mark_auth_type(request, \"bearer\")\n        with SessionLocal() as db:\n            return _resolve_user_from_jwt(credentials.credentials, db)\n\n    if x_api_key is not None:\n        if ADMIN_API_KEY and secrets.compare_digest(x_api_key, ADMIN_API_KEY):\n            _mark_auth_type(request, \"admin_api_key\")\n            return None\n        _mark_auth_type(request, \"api_key\")\n        with SessionLocal() as db:\n            return _resolve_user_from_api_key(x_api_key, db)\n\n    if AUTH_DISABLED:\n        _mark_auth_type(request, \"disabled\")\n        return None\n\n    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.\")","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/server/auth.py#L153-L189","documentation":"Error \"Authentication required. Provide a Bearer token or X-API-Key header.\" thrown in mem0ai/mem0.","triggerScenarios":"Thrown at server/auth.py:171 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Send an Authorization: Bearer <token> header or an X-API-Key header with your request."],"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"}