https://retellai.com/?utm_source=discord&utm_medium=seo logo
I have set up a custom function to call a webhook ...
# ❓・ai-evy-support
z
@AI Evy I have set up a custom function to call a webhook this webhook requires authentication so I et up a bearer token with and Authorization header like this Authorization : Bearer {{access_token}} but it says unaiuthorzed from retell I have tested the function and it works with the authorization but still fails on retell
a
Thanks for tagging me @zigzag8784. I'll look through relevant sources and get back to you shortly.
### Answer Based on the available sources, Retell AI's custom function documentation doesn't show native support for adding custom headers like Authorization headers directly in the custom function configuration [(1) ]() . A community discussion indicates that there isn't an option to add custom headers directly in Retell's custom function setup [(2) ]() . The recommended approach is to create an intermediary layer between Retell and your third-party API . This layer would: 1. Receive the request from Retell's custom function 2. Verify the request is from Retell (using the
X-Retell-Signature
header) [(1) ]() 3. Add your required Authorization header with the bearer token 4. Forward the request to your actual third-party API 5. Return the response back to Retell The Retell custom function will send requests with these headers : - `X-Retell-Signature`: for request verification -
Content-Type: application/json
To verify requests are from Retell, you can use this approach :
Copy code
python
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"})
Your intermediary service would then add the Authorization header before calling your actual webhook endpoint.
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[2] Setting headers in Custom Function](https://discord.com/channels/1186424376300679209/1344403295564726313) ​
z
but why all this? why can it not be direct?
@AI Evy but why all this? why can it not be direct?
a
Thanks for the follow-up, @zigzag8784. I'll get back to you soon.
### Answer Actually, I need to correct my previous response. You can add custom headers directly in Retell AI's custom function configuration. [(1) ]() [(2) ]() When creating a custom function, you can set request headers as part of the configuration. Header values can be static or include dynamic variables. So you should be able to add your Authorization header directly like: - **Header Name**:
Authorization
- **Header Value**:
Bearer {{access_token}}
If it's still showing unauthorized, the issue might be: 1. The dynamic variable
{{access_token}}
isn't properly set
- Make sure you've defined this variable and it contains a valid token 2. The token format - Verify the token value itself is correct (no extra spaces, proper encoding) 3. Token expiration - Check if your bearer token has expired The custom function feature supports setting custom headers, so you shouldn't need an intermediary layer just for authentication. The direct approach should work once the token variable is properly configured.
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[2] Integrate any system with custom function](https://docs.retellai.com/build/single-multi-prompt/custom-function) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.