def test_api_key_lifecycle(client: R2RClient):
    """Test the complete lifecycle of API keys including creation, listing, and
    deletion."""
    # Create user and login
    email = f"{uuid.uuid4()}@example.com"
    password = "api_key_test_password"
    user_id = client.users.create(email, password).results.id
    client.users.login(email, password)

    # Create API key
    api_key_resp = client.users.create_api_key(user_id).results
    assert api_key_resp.api_key is not None, "API key not returned"
    assert api_key_resp.key_id is not None, "Key ID not returned"
    assert api_key_resp.public_key is not None, "Public key not returned"

    key_id = api_key_resp.key_id

    # List API keys
    list_resp = client.users.list_api_keys(user_id).results
    assert len(list_resp) > 0, "No API keys found after creation"
    assert list_resp[0].key_id == key_id, (
        "Listed key ID doesn't match created key")
    assert list_resp[0].updated_at is not None, "Updated timestamp missing"
    assert list_resp[0].public_key is not None, "Public key missing in list"

    # Delete API key using key_id
    delete_resp = client.users.delete_api_key(user_id, key_id).results
    assert delete_resp.success, "Failed to delete API key"

    # Verify deletion
    list_resp_after = client.users.list_api_keys(user_id).results
    assert not any(
        k.key_id == key_id
        for k in list_resp_after), ("API key still exists after deletion")

    client.users.logout()
Test the complete lifecycle of API keys including creation, listing, and
    deletion.
py/tests/integration/test_users.py