https://retellai.com/?utm_source=discord&utm_medium=seo logo
how can I set up an endpoint in retell
# ❓・ai-evy-support
j
@AI Evy how can I set up an endpoint in retell
a
Thanks for tagging me @japhet_07843. I'll look through relevant sources and get back to you shortly.
### Answer There are several types of endpoints you can set up with Retell AI depending on your use case: ## 1. Webhook Endpoints for Call Events To receive call events, you need to create an HTTP/HTTPS endpoint that accepts POST requests [(1) ]() . Here's an example using Node.js:
Copy code
javascript
// install the sdk: <https://docs.retellai.com/get-started/sdk>
import { Retell } from "retell-sdk";
import express, { Request, Response } from "express";
const app = express() ;
app.use(express.json() ) ;
app.post("/webhook", (req: Request, res: Response) => {
 const {event, call} = req.body;
 switch (event) {
 case "call_started":
 console.log("Call started event received", call.call_id) ;
 break;
 case "call_ended":
 console.log("Call ended event received", call.call_id) ;
 break;
 case "call_analyzed":
 console.log("Call analyzed event received", call.call_id) ;
 break;
 default:
 console.log("Received an unknown event:", event) ;
 }
 // Acknowledge the receipt of the event
 res.status(204) .send() ;
}) ;
## 2. Custom Function Endpoints For integrating external APIs and custom logic, you can create custom function endpoints [(2) ]() . These endpoints receive POST requests with function parameters and return results to the LLM . Here's how to verify requests are from Retell using Node.js:
Copy code
javascript
import { Retell } from "retell-sdk";
this.app.post("/check-weather", async (req: Request, res: Response) => {
 if (
 !Retell.verify(
 JSON.stringify(req.body) ,
 process.env.RETELL_API_KEY,
 req.headers["x-retell-signature"] as string,
 )
 ) {
 console.error("Invalid signature") ;
 return;
 }
 const content = req.body;
 if (content.args.city === "New York") {
 return res.json("25f and sunny") ;
 } else {
 return res.json("20f and cloudy") ;
 }
}) ;
## 3. WebSocket Endpoints for Custom LLM For custom LLM integration, you can set up WebSocket endpoints [(3) ]() :
Copy code
javascript
import { RawData, WebSocket } from "ws";
import { Request } from "express";
var express = require('express') ;
var app = express() ;
var expressWs = require('express-ws') (app) ;
const port = 3000
// Your other API endpoints
app.get('/', (req, res) => {
 res.send('Hello World!')
})
app.ws("/llm-websocket/:call_id",
 async (ws: WebSocket, req: Request) => {
 // callId is a unique identifier of a call, containing all information about it
 const callId = req.params.call_id;
 // You need to send the first message here, but for now let's skip that.
 ws.on("error", (err) => {
 console.error("Error received in LLM websocket client: ", err) ;
 }) ;
 ws.on("message", async (data: RawData, isBinary: boolean) => {
 // Retell server will send transcript from caller along with other information
 // You will be adding code to process and respond here
 console.log(data) ;
 }) ;
 },
) ;
app.listen(port, () => {
 console.log(`Example app listening on port ${port}`)
}) ;
After setting up your endpoint locally, you can use ngrok to make it publicly accessible for testing [(1) ]() [(3) ]() .
​ To learn more, see the sources I considered: [[1] Setup guide](https://docs.retellai.com/features/register-webhook) [[2] Integrate any system with custom function](https://docs.retellai.com/build/single-multi-prompt/custom-function) [[3] Setup WebSocket Server](https://docs.retellai.com/integrate-llm/setup-websocket-server) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.