Add Realm Roles via code

I developed an SPI to retrieve users and groups from an external API. Users and groups appear correctly in the admin console. The problem is that I need to manually add Realm Roles for authorization to work correctly. How can I enter Realm Roles via code?

Note: I am using Policy Enforcer and Keycloak 22.0.1.