Provision a Phone Number
Connect a Twilio number to LiveKit and store the linkage on an agent.
Provision a Phone Number
This workflow is implemented in packages/server/src/routes/telephony.route.ts and packages/server/src/services/telephony.service.ts. It wires a Twilio number into a LiveKit SIP trunk, stores all SIDs on the agent row, and updates phoneProvisioningStatus.
Requirements
- Twilio credentials and verified numbers set in environment variables consumed by
createTwilioClient. - LiveKit SIP credentials configured via
getLivekitConfig(see.env.examplekeys such asLIVEKIT_API_KEY,LIVEKIT_API_SECRET, andLIVEKIT_SIP_URI). - The target agent must exist and not already have a phone number.
Endpoint
-
Method:
POST /api/agents/{agentId}/provision-phone -
Body:
{ "phoneNumber": "+15145551234" } -
Validation:
phoneNumbermust be E.164 (++ country code + subscriber digits). US/Canada numbers are forced to+1followed by exactly 10 digits, enforced by thezodschema.
Example request
curl -X POST http://localhost:3001/api/agents/$AGENT_ID/provision-phone \
-H "Authorization: Bearer $TELLYO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"phoneNumber":"+15147548195"}'Response
{
"success": true,
"phoneNumber": "+15147548195",
"twilioTrunkSid": "TKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"livekitInboundTrunkId": "trunk_abc123",
"livekitDispatchRuleId": "rule_def456"
}What happens internally
validateTwilioPhoneNumberconfirms the number exists in your Twilio account and captures the SID.- A Twilio Elastic SIP Trunk and origination URL are created with your LiveKit SIP URI.
- LiveKit inbound trunk + dispatch rule are created so SIP calls can be routed into Agent Rooms.
- The agent row is updated with
twilioPhoneNumber,twilioTrunkSid,livekitInboundTrunkId, andPhoneProvisioningStatus.PROVISIONED. - If any step fails,
rollbackProvisioningtears down everything that was already created and marks the status asFAILED.
Use GET /api/agents/{agentId}/phone-status to inspect the saved SIDs or to check whether provisioning is complete.
Clean up or retry
Run a Deprovision when you need to release the phone number or move it to another agent.