https://retellai.com/?utm_source=discord&utm_medium=seo logo
Code Nodes are Live on Retell AIRun JavaScript dir...
# ❓・ai-evy-support
v
@AI Evy Code Nodes are Live on Retell AI Run JavaScript directly inside your conversation flow. Use it for things like calculations, data formatting, simple API calls, and logic that previously required an external server. → Extract a first name from a full name returned by an API for natural greetings → Calculate a quote in realtime based on caller inputs → Track a retry counter for authentication attempts before escalating or ending the call → …and anything else you’d use JavaScript for elaborate
a
Thanks for tagging me @Vyyy. I'll look through relevant sources and get back to you shortly.
v
@AI Evy where is irt
a
Thanks for the follow-up, @Vyyy. I'll get back to you soon.
### Answer Code Nodes let you execute JavaScript directly in your conversation flow without needing an external server [(1) ]() . They run in Retell's sandbox and are designed for lightweight logic like data transformation, simple API calls, calculations, and formatting . ## How Code Nodes Work Code nodes execute JavaScript when the agent enters them . Unlike custom functions that require HTTP requests to your server, code nodes run directly in Retell's environment . The node isn't intended for conversation, but the agent can still talk while code is running if needed . ## JavaScript Environment Your code has access to several globals : -
dv
— Dynamic variables as properties (all values are strings) -
metadata
— Call metadata passed when the call was created via API -
fetch(url)
— Make HTTP requests to external APIs -
console.log()
— Debugging output visible in test panel and call logs Standard JavaScript built-ins are available:
Math
,
JSON
,
Date
,
Array
,
Object
,
String
methods, etc . External packages (
require
,
import
) are not available . Code is limited to 5,000 characters . ## Practical Examples Extract first name from full name:
Copy code
javascript
const fullName = dv.customer_name; // "John Doe"
const firstName = fullName.split(" ") [0];
return { first_name: firstName };
Calculate quote based on inputs:
Copy code
javascript
const weight = parseFloat(dv.order_weight) ;
const zone = dv.shipping_zone;
let cost;
if (zone === "local") {
 cost = weight * 0.5;
} else if (zone === "domestic") {
 cost = weight * 1.2;
} else {
 cost = weight * 3.0;
}
return { shipping_cost: "$" + cost.toFixed(2) , zone: zone };
Conditional logic with API call:
​ To learn more, see the sources I considered: [[1] Code Node](https://docs.retellai.com/build/conversation-flow/code-node) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
Copy code
javascript
const response = await fetch("<https://api.example.com/customers/%22> + dv.customer_id) ;
const customer = await response.json() ;
if (customer.tier === "premium") {
 return { action: "priority_support", wait_time: "0 minutes" };
} else if (customer.tier === "standard") {
 return { action: "standard_queue", wait_time: "5 minutes" };
} else {
 return { action: "general_queue", wait_time: "10 minutes" };
}
## Response Variables You can extract values from your code's return value and save them as dynamic variables using Store Fields as Variables . Specify a variable name and JSON path to the value . For example, if your code returns
{ "status": "shipped", "estimated_delivery": "March 25" }
, you can extract
order_status
from path
status
to get
"shipped"
. ## Node Settings - **Speak During Execution**: Agent says something while code runs (Prompt or Static Text) - **Wait for Result**: Agent waits for code to finish before transitioning - **Timeout**: How long code can run before timing out (5–60 seconds, default 30) - **Block Interruptions**: Prevents user interruptions when speaking ## Security Guidance Code Node is best for lightweight, low-risk logic . Don't use it to access internal systems, write to production databases, or handle sensitive credentials . Both
dv
and
metadata
values are stored in plaintext with every call record . For integrations requiring authentication, secrets management, or write access, use a Custom Function hosted on your own backend .
### Answer Code Node is found in the Retell AI dashboard under the Conversation Flow builder. [(1) ]() To add a Code Node to your conversation flow, click the Code node from the left sidebar to add it to the canvas. Once added, click Open on the code node to launch the code editor where you can write your JavaScript code. The Code Node executes JavaScript code directly in Retell's sandbox when the agent enters it. You have access to dynamic variables, call metadata, and the
fetch
function for HTTP requests. For example, here's how you might look up an order and return its status:
Copy code
javascript
// Example: look up an order and return the status
const response = await fetch("<https://api.example.com/orders/%22> + dv.order_id) ;
const data = await response.json() ;
return { status: data.status, estimated_delivery: data.delivery_date };
You can also use Store Fields as Variables to extract values from your code's return value and save them as dynamic variables. For instance, if your code returns
{ "status": "shipped", "estimated_delivery": "March 25" }
, you can specify variable names and JSON paths to extract specific values. Code Node is designed for lightweight logic like formatting, calculations, and simple read-only lookups. For complex integrations requiring authentication, secrets management, or write access, use a Custom Function hosted on your own backend instead.
​ To learn more, see the sources I considered: [[1] Code Node](https://docs.retellai.com/build/conversation-flow/code-node) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.