To add an API key to a Discovery-loaded beta endpoint in the Google JS client library, pass the API key when loading the client with gapi.client.init().
Here is the code snippet you can refer to:

In the above code we are using the following key points:
- Uses gapi.client.init() to load the Discovery document and attach the API key.
- Handles API calls using the loaded client and the specified endpoint.
- Uses async/await for cleaner asynchronous handling.
- Logs success and error states for visibility.
Hence, adding an API key to a Discovery-loaded beta endpoint ensures secure and authenticated API requests through the Google JS client library.