https://retellai.com/?utm_source=discord&utm_medium=seo logo
<@1145576664366055464> how to make web calls using...
# ❓・ai-evy-support
a
@AI Evy how to make web calls using retell
a
Thanks for tagging me @andreapalacio. I'll look through relevant sources and get back to you shortly.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Connect to web call]() * [Migration guide]() * [Setup WebSocket Server]() * [LLM WebSocket]() -----------------------------
### Answer # Making Web Calls with Retell AI To make web calls using Retell AI, you need to follow these steps: ## Set up the SDK First, install the Retell Web SDK:
Copy code
javascript
npm install retell-client-js-sdk
[(1)]() Then set up the SDK class:
Copy code
javascript
import { RetellWebClient } from "retell-client-js-sdk";

const retellWebClient = new RetellWebClient();
## Call create-web-call to get call ID Your client code should call your server endpoint which internally calls the create web call API to get the access token for the call. This requires your Retell API key, which is why you need to call the endpoint from the server instead of the client (to protect your API key). Note that if you don't start the call within 30 seconds of obtaining the access token, it will be invalidated and the call will be marked with an error. According to community discussions, you should use the "create-call" endpoint instead of the older "register-call" endpoint. [(2)]() ## Start the Call Once you have the access token, you can start the call:
Copy code
javascript
await retellWebClient.startCall({
  accessToken: createCallResponse.access_token,
});
[(1)]() There are optional parameters you can include:
Copy code
javascript
await retellWebClient.startCall({
  accessToken: createCallResponse.access_token,
  sampleRate: 24000, // (Optional) set sample rate of the audio capture and playback
  // (Optional) device id of the mic.
  captureDeviceId: "default",
  // (Optional) device id of the speaker
  playbackDeviceId: "0ec1807fd0fe6e51b990660ec4e2ebb78sdfcba51e279815d00c423ce03407ff",
  // (Optional) Whether to emit "audio" events that contain raw pcm audio bytes represented by Float32Array
  emitRawAudioSamples: false,
});
## Listen to Events You can listen to events emitted by the SDK to get real-time updates about the call:
Copy code
javascript
retellWebClient.on("call_started", () => {
  console.log("call started");
});

retellWebClient.on("call_ended", () => {
  console.log("call ended");
  setIsCallActive(false);
});

// When agent starts talking for the utterance
retellWebClient.on("agent_start_talking", () => {
  console.log("agent_start_talking");
});

// When agent is done talking for the utterance
retellWebClient.on("agent_stop_talking", () => {
  console.log("agent_stop_talking");
});

// Update message such as transcript
retellWebClient.on("update", (update) => {
  // console.log(update);
});

retellWebClient.on("metadata", (metadata) => {
  // console.log(metadata);
});

retellWebClient.on("error", (error) => {
  console.error("An error occurred:", error);
  // Stop the call
  retellWebClient.stopCall();
});
## Stop the Call To end the call:
Copy code
javascript
retellWebClient.stopCall();
**Note**: According to community discussions, there may be some discrepancies between the documentation and the current implementation. The most recent approach is to make the server-side request to "/create-call" rather than "/register-call". [(2)]()
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.