Architecture
PSTN callers dial your number; your SIP provider forwards the call to the Zero Runtime SIP Gateway, and a routing rule routes it to your self-hosted agent by matching itsagent_id.For outbound calls, your agent dials through an outbound gateway to the SIP provider, which places the PSTN call.
Prerequisites
- Python 3.11 or higher.
- A ZRT Auth token (
ZRT_AUTH_TOKEN). Generate one in the Zero Runtime Dashboard. - A SIP provider (such as Twilio) with a phone number, plus access to its origination and termination settings.
Setup the project
Use Python 3.11 or higher, then install the Zero Runtime Agents SDK. Create and activate a virtual environment, then install
zrt and python-dotenv. Every provider plugin ships with zrt.Configure environment variables
Store API keys and tokens in a
.env file in your project root.- Cascade
- Realtime
.env
Build the agent
For telephony, the agent must register itself so calls can be routed to it. With your Keep the process running. It registers with Zero Runtime using the ID 
zrt.serve() registers the agent under its agent_id automatically. The agent half is the same as any voice agent. Pick your language.For telephony, the agent must register itself with Zero Runtime so calls can be routed to it. Give the agent a unique agent_id and start it with zrt.serve(), which registers it automatically. Inbound calls arrive through routing, so there is no need to self-invoke a session.- Cascade
- Realtime
main.py
.env configured and dependencies installed, run the agent:MyTelephonyAgent.
Add SIP Configuration
- Go to the Zero Runtime Dashboard.
- Click Add Number.
- Click Configure SIP.
- Give a name and add your phone number.
Configure Zero Runtime gateways
Set up two gateways and point your SIP provider (Twilio in this example) at them so calls flow both ways. Use the Dashboard or the API for each.1. Inbound gateway: the entry point for incoming calls.2. Outbound gateway: lets the agent dial out to the PSTN.
- Dashboard
- API
- Copy the Inbound URL from the Zero Runtime dashboard.
- Go to Twilio and create a new SIP Trunk.
- Go to the Origination section, paste the Inbound URL there, and save it.
- Dashboard
- API
- In Twilio, open the same SIP Trunk and go to the Termination section. Create a Termination URI and add username/password credentials.
- Back in the Zero Runtime Dashboard, open the outbound gateway configuration.
- Paste the Twilio Termination URI as the address, add the same username/password credentials, and save.
Create a routing rule
Connect the inbound gateway to your agent by ID. The agent ID must match the
agent_id you pass to your agent (registered by zrt.serve()).- Dashboard
- API
- From your inbound gateway, click Configure rule, then Create new routing rule.
- Enter a Routing Rule Name and select API Key authentication.
- Choose the Call Direction (Inbound).
- Enter the Phone Number and select a Room Type.
- Enter the Agent ID (e.g.
MyTelephonyAgent) and click Save.
Place a test call
Make sure your main.py is running locally before configuring the telephony settings. The agent must be active to receive incoming calls.
- Inbound
- Outbound
Dial your provider’s phone number from any phone. The worker waits for the caller to join, then greets you as soon as the call connects.
Verify
- The agent registers under the ID
MyTelephonyAgentand the worker process stays running. - An incoming call reaches the agent and you hear the greeting.
- Outbound calls dial the target number through your outbound gateway.
What’s Next
Telephony overview
Explore SIP connect, call routing, and integrations.
Managing calls
Handle call transfer, DTMF events, and webhooks.