While AppExchange Product development or dynamic setup, we typically get this scenario to create Remote site setting programmatically. The legacy method is using Metadata service which pretty costly technically.
With the evolution of Tooling API, we are blessed to achieve this using Tooling API as below:

Code Example


Please reach out to us if you need any help to achieve this: Get in touch.