def api_auth(request: Request):
    """
    Authenticates the API request using a Bearer token.

    Args:
        request (Request): The incoming HTTP request object.

    Returns:
        str: The verified Bearer token if authentication is successful.

    Raises:
        HTTPException: If the token is invalid, expired, or missing.
    """
    authorization = request.headers.get("Authorization")
    if authorization:
        schema, _, token = authorization.partition(" ")
        if schema.lower() == "bearer":
            token = token.strip()
            try:
                _ = token_verification(token=token)
                return token
            except Exception as e:
                logger.error(f"Failed to verify token: {e}")
                raise HTTPException(
                    status_code=status.HTTP_401_UNAUTHORIZED,
                    detail="Invalid or expired token: Bearer",
                )
    raise HTTPException(
        status_code=status.HTTP_401_UNAUTHORIZED,
        detail="Invalid or expired token",
    )

    Authenticates the API request using a Bearer token.

    Args:
        request (Request): The incoming HTTP request object.

    Returns:
        str: The verified Bearer token if authentication is successful.

    Raises:
        HTTPException: If the token is invalid, expired, or missing.
    
src/autotrain/app/api_routes.py