Skip to main content

Set up the SDK

Step 1: Install the Retell Web SDK npm install retell-client-js-sdk Step 2: Set up the SDK class

Call create-web-call to get call id

Your client code should call your server endpoint which internally calls create web call to get the access token for the call. The endpoint requires using your Retell API Key, which is the reason why you need to call the endpoint from the server instead of the client to protect the key from exposing. The access token obtained will be used in your frontend client code to start the call.
Note that if you do not start the call within 30s of obtaining the access token, we will invalidate it and the call will be marked with error.

Start the Call

Once call starts, you can listen to a couple of events that are emitted for real time updates about the call.
There are other optional options that allow you to set the sample rate of the call, audio capture and playback device, whether to receive raw audio bytes from the client.

Stop the Call

You can close a web call with the agent by using

Listen to events

You can listen to events emitted by the SDK to get real time updates about the call, including who is speaking, the real time transcript, start and end of the call.

Audio Basics

If you have not worked with audio bytes before, we strongly suggest you check out audio basics, which can help with choosing the best configuration here. PCM audio format conversion functions convertUnsigned8ToFloat32 and convertFloat32ToUnsigned8 can be found in audio basics.