When to use this workflow
Use this workflow when you manage agent configuration in source code or provision agents for multiple customers. If you already have an agent and only need to place calls, use the create phone call API instead. The example creates an after-hours receptionist for a heating company. It collects the caller’s name, callback number, address, and reason for calling without promising a price or appointment time.Before you start
You need:- Node.js 18.10 or later.
- A Retell API key.
- A voice ID from the voice library.
- An HTTPS endpoint if you want to receive call event webhooks. The webhook is optional in this example.
Create the agent
1
Install the SDK and TypeScript runner
Create a Node.js project and install the dependencies:
2
Set environment variables
Export the API key and voice ID you copied from the dashboard. Set the webhook URL only if your endpoint is ready to receive call events.Keep the API key in your server environment or secret manager. Do not expose it in browser code or commit it to source control.
3
Create the response engine and agent
Save this file as The example sets English explicitly, caps calls at 15 minutes, and ends a call after 2 minutes of silence. As of July 2026,
create-agent.ts:max_call_duration_ms accepts 1 minute to 2 hours, while end_call_after_silence_ms has a 10-second minimum and a 10-minute default. Because model is omitted, the Retell LLM uses the endpoint’s default text model.If RETELL_WEBHOOK_URL is set, the agent-level webhook replaces the account-level webhook for this agent.4
Run the script
Run the TypeScript file:A successful run prints the Retell LLM ID, agent ID, and draft version:
Test and publish the agent
Open the new agent in the dashboard and run a web call test. A draft can be tested without publishing or assigning a phone number. When the draft is ready, publish it from the dashboard version panel or call the publish agent API with theagent_id and version printed by the script. Published versions are immutable. See agent versioning before you attach a version or environment tag to a phone number.
If you configured a webhook, verify its signature before processing call events.
Common questions
Why does the example make two API calls?
Why does the example make two API calls?
The response engine and voice agent are separate resources.
client.llm.create() defines what the agent says and which tools it can use. client.agent.create() attaches that response engine to voice and call settings.What happens if agent creation fails after the Retell LLM is created?
What happens if agent creation fails after the Retell LLM is created?
The Retell LLM remains available because the two create calls are not atomic. Reuse its
llm_id on the next attempt, or remove it with the delete Retell LLM API.Do I need to publish before testing?
Do I need to publish before testing?
No. Test the draft with a browser web call first. Publish it when you are ready to use an immutable version for a phone number or environment tag.

