mem0ai/mem0 · error · HTTPException

Authentication required. Provide a Bearer token or X-API-Key

Error message

Authentication required. Provide a Bearer token or X-API-Key header.

What it means

Error "Authentication required. Provide a Bearer token or X-API-Key header." thrown in mem0ai/mem0.

Source

Thrown at server/auth.py:171

    """
    if credentials is not None:
        _mark_auth_type(request, "bearer")
        with SessionLocal() as db:
            return _resolve_user_from_jwt(credentials.credentials, db)

    if x_api_key is not None:
        if ADMIN_API_KEY and secrets.compare_digest(x_api_key, ADMIN_API_KEY):
            _mark_auth_type(request, "admin_api_key")
            return None
        _mark_auth_type(request, "api_key")
        with SessionLocal() as db:
            return _resolve_user_from_api_key(x_api_key, db)

    if AUTH_DISABLED:
        _mark_auth_type(request, "disabled")
        return None

    raise HTTPException(
        status_code=401,
        detail="Authentication required. Provide a Bearer token or X-API-Key header.",
        headers={"WWW-Authenticate": "Bearer"},
    )


async def require_auth(
    request: Request,
    user: User | None = Depends(verify_auth),
) -> User:
    """Like verify_auth but guarantees a non-None User. Use for endpoints that require auth."""
    if user is None:
        if getattr(request.state, "auth_type", "none") in {"admin_api_key", "disabled"}:
            with SessionLocal() as db:
                default_user = _get_default_user(db)
            if default_user is not None:
                return default_user
        raise HTTPException(status_code=401, detail="Authentication required.")

View on GitHub (pinned to 001c235229)

Solutions

  1. Send an Authorization: Bearer <token> header or an X-API-Key header with your request.

When it happens

Trigger: Thrown at server/auth.py:171 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/f2c3e151c4c4e255. Report an issue: GitHub.