https://retellai.com/?utm_source=discord&utm_medium=seo logo
my signature validation is failing
# ❓・ai-evy-support
e
@AI Evy my signature validation is failing
a
Thanks for tagging me @edwardsalfred. I'll look through relevant sources and get back to you shortly.
### Answer To verify that the request is coming from Retell, you need to check the
X-Retell-Signature
header [(1) ]() [(2) ]() . Here are the most common causes and solutions for signature validation failures: 1. Use the correct API key Make sure you're using the designated webhook API key (not just any API key) in your
Retell.verify()
function [(3) ]() . 2. Correct JSON serialization The most common cause is incorrect JSON serialization . Make sure you're using: For Python:
Copy code
python
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from retell import Retell
retell = Retell(api_key=os.environ["RETELL_API_KEY"])

@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"})
[(2) ]() For Node.js:
e
this is my new error the signature still doesn't match. The provided digest doesn't match our expected digest, which means the secret they're using is different from. i created a new private api key and made it my new secret but its not working in my lovable database
this is my new error the signature still doesn't match. The provided digest doesn't match our expected digest, which means the secret they're using is different from. i created a new private api key and made it my new secret but its not working in my lovable database
a
Thanks for the follow-up, @edwardsalfred. I'll get back to you soon.
Copy code
python
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from retell import Retell
retell = Retell(api_key=os.environ["RETELL_API_KEY"])
@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"})
[(4) ]() 3. Verify your environment configuration Ensure your environment variable
RETELL_API_KEY
is set to the webhook-designated API key, not just any API key. The webhook verification requires the specific key that has the webhook badge [(1) ]() . 4. Alternative security option You can also secure your server by allowlisting Retell IP addresses:
100.20.5.228
[(1) ]() [(4) ]() .
### Answer Based on your signature validation error, there are several specific steps to troubleshoot this issue: 1. Use the correct webhook API key Only the API key that has a webhook badge next to it can be used to verify the webhook [(1) ]() . Make sure you've designated your new API key as the webhook key by clicking "Set as Webhook Key" in your API Keys section [(2) ]() . 2. Use the official Retell SDK verification Instead of implementing your own HMAC calculation, use the official Retell SDK verification function [(3) ]() . Here's the exact code from the documentation: For 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) => {
 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 {event, call} = req.body;
 // process the webhook
 // Acknowledge the receipt of the event
 res.status(204) .send() ;
}) ;
[(1) ]() For Python:
​ To learn more, see the sources I considered: [[1] Secure the webhook](https://docs.retellai.com/features/secure-webhook) [[2] Manage API Keys](https://docs.retellai.com/accounts/manage-api-keys) [[3] Webhook Verification](https://discord.com/channels/1186424376300679209/1400483295082451026) [[4] 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.