https://retellai.com/?utm_source=discord&utm_medium=seo logo
how do you use dynamic variables in inbound calls
# ❓・ai-evy-support
k
@AI Evy how do you use dynamic variables in inbound calls
a
Thanks for tagging me @kakashi1412. I'll look through relevant sources and get back to you shortly.
### Answer To use dynamic variables in inbound calls, you have two main options: ## Option 1: Inbound Call Webhook (Recommended) Set up an Inbound Webhook on your phone number configuration. When an inbound call comes in, Retell sends a POST request to your endpoint with the caller info (
from_number
,
to_number
) . You then respond with dynamic variables for that specific call. [(1) ]() Your webhook response should look like this:
Copy code
json
{
  "call_inbound": {
    "dynamic_variables": {
      "customer_name": "John Doe"
    }
  }
}
**Important**: All dynamic variable values must be strings. Passing boolean values like
false
instead of
"false"
can cause issues. [(2) ]() ## Option 2: Custom SIP Headers You can use custom SIP headers to pre-set dynamic variables for inbound calls. The header needs to start with
sip.h.x-
, and it will be converted to a dynamic variable after removing the prefix. [(3) ]() For example:
sip.h.x-caller: abc
becomes
x-caller: abc
. ## Using the Variables Once set, reference them in your prompts using double curly braces:
Copy code
Hello {{customer_name}}, how can I help you today?
[(1) ]()
​ To learn more, see the sources I considered: [[1] Inbound webhook](https://docs.retellai.com/features/inbound-call-webhook) [[2] Dynamic Variables From Inbound Webhook Not Passed to the Call](https://discord.com/channels/1186424376300679209/1419725903918923920) [[3] Receive calls](https://docs.retellai.com/deploy/inbound-call) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
k
@AI Evy i have an inbound call agent, in which i need multiple tool calls to go through for initialization. can this happen without the speech getting interrupted, ie, in the background while the agent talks to the user
a
Thanks for the follow-up, @kakashi1412. I'll get back to you soon.
### Answer --- Yes, you can configure tool calls to run in the background while the agent continues speaking. This is controlled by the Speak during execution and Speak after execution settings for custom functions. [(1) ]() Key configuration: - **Speak during execution**: Enable this so the agent speaks at the moment the function is called, rather than waiting silently. - **Speak after execution**: Enable this so the agent continues talking or takes other actions after the function completes, without waiting for user input. These settings control agent behavior when the user is not talking during the function call period. For multiple initialization tool calls: You'll want to structure your prompt to explicitly instruct the agent when and how to invoke these functions. One community thread noted that if multiple tool calls are being invoked unexpectedly, you may need to explicitly state in your prompt to "call this function ONE time then say '…'" to prevent repeated invocations. [(2) ]() **Important**: The sources don't explicitly document running multiple tool calls simultaneously in the background during initialization. If you need sequential initialization calls while the agent speaks, you'd configure each function with "Speak during execution" enabled so the agent can talk while each call processes. [(1) ]()
​ 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] Multiple tool calls invoked while an agent is still reading the response](https://discord.com/channels/1186424376300679209/1429919905179893974) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
k
@AI Evy how can i extract the phone number of the caller in the inbound call webhook? this is necessary for my workflow, as it requires the phone number value at the time of tool calls
a
Thanks for the follow-up, @kakashi1412. I'll get back to you soon.
### Answer The caller's phone number is included in the inbound webhook payload as
from_number
. [(1) ]() Webhook payload example:
Copy code
json
{
  "event": "call_inbound",
  "call_inbound": {
    "agent_id": "agent_12345",
    "agent_version": 1,
    "from_number": "+12137771234",
    "to_number": "+12137771235"
  }
}
The
from_number
field will always show up in the payload and helps you identify the caller. To use it in tool calls: You can pass the
from_number
value back as a dynamic variable in your webhook response, making it available throughout the call:
Copy code
json
{
  "call_inbound": {
    "dynamic_variables": {
      "caller_phone": "+12137771234"
    }
  }
}
Then reference
{{caller_phone}}
in your tool configurations or prompts. [(2) ]() System variable alternative: For phone calls, Retell also provides a built-in system variable
{{user_number}}
which automatically contains the user's phone number (for inbound calls, this is the
from_number
) .
​ To learn more, see the sources I considered: [[1] Inbound webhook](https://docs.retellai.com/features/inbound-call-webhook) [[2] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
k
@AI Evy sending the dynamic variables back in the response to the inbound webhook is not setting them, what is the issue and how does this work
a
Thanks for the follow-up, @kakashi1412. I'll get back to you soon.
### Answer --- When dynamic variables aren't being set from your inbound webhook response, here are the common issues and how it works: Required Response Format Your webhook response must nest the
dynamic_variables
under `call_inbound`: [(1) ]()
Copy code
json
{
  "call_inbound": {
    "dynamic_variables": {
      "customer_name": "John Doe"
    }
  }
}
Common Issues 1. Invalid response format — The error
Invalid webhook response format
indicates the response structure doesn't match what Retell expects. Make sure
dynamic_variables
is nested inside
call_inbound
, not at the root level. [(2) ]() 2. Non-string values — All dynamic variable values must be strings. If you're passing values from a workflow tool like Make.com using template variables (e.g.,
{{81.firstName}}
) , ensure those values are actually populated and are strings. 3. Webhook timeout — The webhook has a 10-second timeout. If no success status (2xx) is received within that time, the webhook retries up to 3 times. [(1) ]() Troubleshooting Steps - Check your call's Data Log in the call history tab — it will show if the inbound webhook triggered successfully or returned an error. [(2) ]() - Test with hardcoded string values first to confirm the format is correct before using dynamic template variables. - Create a new version of your agent and test again.
​ To learn more, see the sources I considered: [[1] Inbound webhook](https://docs.retellai.com/features/inbound-call-webhook) [[2] agent not receiving dynamic variables from inbound webhook response](https://discord.com/channels/1186424376300679209/1394015802402930778) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.