https://retellai.com/?utm_source=discord&utm_medium=seo logo
my custom function only returns call id and not su...
# ❓・ai-evy-support
v
@AI Evy my custom function only returns call id and not success or error
a
Thanks for tagging me @vyyy_20754. I'll look through relevant sources and get back to you shortly.
### Answer Based on the documentation, your custom function should return a proper HTTP response to indicate success or failure [(1) ]() [(2) ]() . For a successful custom function call, your endpoint should return a status code between 200-299 . The response can be in various formats including string, buffer, JSON object, or blob, and all formats will be converted to string before sending to the LLM . Here's how to properly structure your custom function response:
Copy code
javascript
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") ;
 }
}) ;
[(1) ]() Or in Python:
Copy code
python
@app.post("/check-weather")
async def check-weather(request: Request) :
 try:
 post_data = await request.json()
 valid_signature = retell.verify(
 json.dumps(post_data, separators=(",", ":") , ensure_ascii=False) ,
 api_key=str(os.environ["RETELL_API_KEY"]) ,
 signature=str(request.headers.get("X-Retell-Signature") ) ,
 )
 if not valid_signature:
 print(
 "Received Unauthorized",
 post_data["event"],
 post_data["data"]["call_id"],
 )
 return JSONResponse(status_code=401, content={"message": "Unauthorized"})
 args = post_data["args"]
 if args["city"] == "New York":
 return JSONResponse(status_code=200, content={"result": "25f and sunny"})
 else:
 return JSONResponse(status_code=200, content={"result": "20f and cloudy"})
 except Exception as err:
 print(f"Error in webhook: {err}")
 return JSONResponse(
 status_code=500, content={"message": "Internal Server Error"}
 )
Key points: - Return HTTP status codes 200-299 for success [(1) ]() [(2) ]() - Return appropriate error status codes (4xx, 5xx) for failures - The function result is capped at 15000 characters - When the request fails, it will be retried up to 2 times If your function is only returning a call ID without success/error indication, ensure your endpoint is returning proper HTTP status codes and response content.
​ To learn more, see the sources I considered: [[1] Integrate any system with custom function](https://docs.retellai.com/build/single-multi-prompt/custom-function) [[2] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.