https://retellai.com/?utm_source=discord&utm_medium=seo logo
how to set a dynamic variable when it gets returne...
# ❓・ai-evy-support
e
@AI Evy how to set a dynamic variable when it gets returned from a functoin response?
a
Thanks for tagging me @Emanuel. I'll look through relevant sources and get back to you shortly.
### Answer To set a dynamic variable from a function response, use Response Variables in your Custom Function configuration. [(1) ]() Steps: 1. In your Custom Function node, locate the "Set response variables" option 2. Extract values from the API response and save them as dynamic variables for use later in the conversation For example, if your API returns:
Copy code
json
{
  "properties": {
    "user": {
      "name": "John Doe",
      "age": 26
    }
  }
}
You can extract
user.name
and save it as a dynamic variable like
{{user_name}}
, then reference it later in the conversation. Important tip from the community: When using the extracted variable in subsequent custom functions, reference it using the
{{variable_name}}
syntax in both the parameter value and description fields. For example:
Use this as the treatment id: {{treatment_id}}
[(5) ]()
​ To learn more, see the sources I considered: [[1] 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.
e
@AI Evy more detail on each step
a
Thanks for the follow-up, @Emanuel. I'll get back to you soon.
### Answer Here's a more detailed breakdown for setting dynamic variables from a function response: Step 1: Configure your Custom Function endpoint [(1) ]() Set up your server to return a JSON response. For example:
Copy code
python
return JSONResponse(status_code=200, content={"result": "25f and sunny"})
Step 2: Set response variables [(2) ]() In your function configuration, use the "Set response variables" option to extract values from the response and save them as dynamic variables for use later in the conversation. For example, if your response body looks like:
Copy code
json
{
  "properties": {
    "user": {
      "name": "John Doe",
      "age": 26
    }
  }
}
You can extract
user.name
and save it as
{{user_name}}
. Step 3: Reference the variable later [(3) ]() Once saved, use the
{{variable_name}}
syntax anywhere dynamic variables are supported: - Prompts - Begin message - Tool configurations (URLs, descriptions) - Transfer call phone numbers Important distinction from community feedback: [(4) ]() - **Response Variables**: Used after a function is called to extract values from its output - **Extract Dynamic Variable**: Called before a function to set variables ahead of time
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[2] MCP](https://docs.retellai.com/build/single-multi-prompt/mcp) [[3] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) [[4] I'm having trouble with Custom Functions that need dynamic path variables in GET endpoints](https://discord.com/channels/1186424376300679209/1420898782828040192) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
e
@AI Evy im extracing a number to get transferred. what response
a
Thanks for the follow-up, @Emanuel. I'll get back to you soon.
### Answer --- To extract a phone number for transfer, your custom function endpoint should return a response that includes the phone number you want to use. [(1) ]() Example response format:
Copy code
json
{
  "transfer_number": "+14157774444"
}
Then in your Custom Function's Response Variables section, extract that value and save it as a dynamic variable (e.g.,
{{transfer_number}}
) . Once saved, you can use
{{transfer_number}}
in your Transfer Call phone number field—dynamic variables work in transfer call phone numbers. [(2) ]() Note: If your response returns an array instead of an object, you'll need to reference it with an index like
transfer_numbers[0]
when setting the response variable. [(7) ]()
​ To learn more, see the sources I considered: [[1] Custom Function](https://docs.retellai.com/build/conversation-flow/custom-function) [[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.
e
@AI Evy do i have to call the 'extract dynamic varialbe ' tool?
a
Thanks for the follow-up, @Emanuel. I'll get back to you soon.
### Answer No, you don't need to call the "Extract Dynamic Variable" tool when you're getting a value from a function response. [(1) ]() Here's the distinction: - **Extract Dynamic Variable**: Used to extract information from the conversation (what the user says) and store it as a dynamic variable. [(2) ]() [(3) ]() - **Response Variables**: Used to extract values from an API/function response and save them as dynamic variables. [(1) ]() Since you're extracting a phone number from a custom function's response, you should use Response Variables in your Custom Function configuration—not the Extract Dynamic Variable tool. The Extract Dynamic Variable tool is specifically for pulling data from what users say during the conversation, not from API responses. [(2) ]()
​ To learn more, see the sources I considered: [[1] MCP](https://docs.retellai.com/build/single-multi-prompt/mcp) [[2] Extract Dynamic Variable Node](https://docs.retellai.com/build/conversation-flow/extract-dv-node) [[3] Extract Dynamic Variables](https://docs.retellai.com/build/single-multi-prompt/extract-dv) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.