def login(
    api_url: str, api_key: str, workspace: Optional[str] = None, extra_headers: Optional[Dict[str, str]] = None
) -> None:
    """Login to an Argilla server using the provided URL and API key. If the login is successful, the credentials will
    be stored in the Argilla cache directory (`~/.cache/argilla/credentials.json`).

    Args:
        api_url: The URL of the Argilla server.
        api_key: The API key to use when communicating with the Argilla server.
        workspace: The default workspace where the datasets will be created.
        extra_headers: A dictionary containing extra headers that will be sent to the Argilla server.

    Raises:
        ValueError: If the login fails.
    """
    # Try to login to the server
    try:
        init(api_url=api_url, api_key=api_key, workspace=workspace, extra_headers=extra_headers)
    except HttpResponseError as e:
        raise ValueError(
            f"Could not reach '{api_url}', make sure that the Argilla Server is running and working as expected"
        ) from e
    except UnauthorizedApiError as e:
        raise ValueError(f"Could not login in '{api_url}' using provided credentials") from e

    if not ARGILLA_CACHE_DIR.exists():
        ARGILLA_CACHE_DIR.mkdir(parents=True)

    ArgillaCredentials(api_url=api_url, api_key=api_key, workspace=workspace, extra_headers=extra_headers).save()
Login to an Argilla server using the provided URL and API key. If the login is successful, the credentials will
    be stored in the Argilla cache directory (`~/.cache/argilla/credentials.json`).

    Args:
        api_url: The URL of the Argilla server.
        api_key: The API key to use when communicating with the Argilla server.
        workspace: The default workspace where the datasets will be created.
        extra_headers: A dictionary containing extra headers that will be sent to the Argilla server.

    Raises:
        ValueError: If the login fails.
    
argilla-v1/src/argilla_v1/client/login.py