How do we get the audio urls if using twilio SIP?
# ask-ai
d
How do we get the audio urls if using twilio SIP?
t
Thanks for reaching out, Billy. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to get audio URLs when using Twilio SIP. Here’s the direct path you can use. • LiveKit does not expose live stream URLs for SIP calls. To get audio files you must record the call using LiveKit egress (manual Room Composite Egress or AutoEgress). • Start a Room Composite egress (or enable AutoEgress on your dispatch/room config) targeting a file output (S3/GCP/Azure or public file URL). Example: start a Room Composite egress that writes
call-recording.mp3
or an S3 path. • After the recording finishes you get the file URL: ◦ Listen for the
egress_ended
webhook event (includes
download_url
), or ◦ Query the egress status via the egress API/CLI to retrieve the
download_url
for that
egress_id
. • Notes: ◦ You can include Twilio metadata like
CallSid
in participant attributes (
sip.twilio.callSid
) for correlation, but you still retrieve audio via LiveKit egress outputs. ◦ If you need cleaner audio, enable
krisp_enabled
or configure recording settings when creating the SIP participant/room. Would you like the exact API payload for starting a Room Composite egress to S3 or an example webhook payload for
egress_ended
? Sources: Make outbound calls | LiveKit docs | server-sdk-js | livekit/livekit_composite | DeepWiki | examples/bank-ivr | livekit/livekit_composite | DeepWiki | Track egress | LiveKit docs | SIP participant | LiveKit docs
d
ok can one not use the twilio callsid and make a twilio api call instead?
t
You can use a Twilio CallSid to fetch recordings from Twilio only if Twilio itself recorded the call. For calls handed off to LiveKit via SIP, LiveKit terminates and handles the media, so Twilio won't have a recording to return from the CallSid. What you can do: • Have Twilio record on its side (if you enable Twilio-side recording before handing media off). Then you can use the CallSid with Twilio's Recording APIs to get URLs. • Or record in LiveKit via egress (recommended for SIP→LiveKit flows). LiveKit egress produces a
download_url
(webhook or API/CLI) you can use and correlate with
sip.twilio.callSid
in participant attributes. Which approach do you prefer—enable Twilio recording or set up LiveKit egress? I can provide the exact Twilio API calls or the LiveKit egress payload/webhook example next.
d
but twilio must have the recording because its twilio SIP, inbound using twilio #. so ill just look into that
t
You're right — Twilio will only return a recording for a CallSid if Twilio actually recorded that call. Quick facts and options: • If Twilio recording was enabled for that inbound SIP call, you can use the CallSid with Twilio's Recordings API to list/download recordings and get recording URLs. • If Twilio did NOT record (because media was handed off to LiveKit), Twilio won't have a recording for that CallSid. • Alternative (recommended for SIP→LiveKit): enable LiveKit egress to record the room and get a
download_url
(webhook or API/CLI) and correlate it with
sip.twilio.callSid
in participant attributes. If you want, I can: • Show the Twilio API call example to fetch recordings by CallSid, or • Provide the LiveKit Room Composite egress payload and example
egress_ended
webhook. Which would you like?
d
ok
both
t
Responding with both Twilio and LiveKit options: examples and where to look. 1) Twilio — fetch recordings by CallSid • Use the CallSid to list recordings (only works if Twilio recorded the call). • Example (cURL) to list recordings for a CallSid:
Copy code
curl -G https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Recordings.json \
  -u '{AccountSid}:{AuthToken}' \
  --data-urlencode "CallSid=CAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
• The response includes recording SIDs and
uri
fields. To fetch a specific recording media URL:
Copy code
curl -u '{AccountSid}:{AuthToken}' \
  https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}.mp3
• Or use the Recordings list endpoint and look for `media_url`/`uri` in the JSON; Twilio also provides REST links for download. 2) LiveKit — record via egress and get a download_url • Start a Room Composite egress (or enable AutoEgress) to produce a file output (S3/GCP/Azure or public file). • Example JSON payload to start a Room Composite egress writing an MP3 to S3:
Copy code
{
  "room_name": "my-sip-call-room",
  "output": {
    "file": {
      "filename": "s3://my-bucket/call-recording-{room_name}.mp3"
    }
  }
}
• After egress completes you get an
egress_id
and output info. Retrieve the `download_url`: ◦ Listen for the
egress_ended
webhook event (payload includes
output.download_url
), or ◦ Query the egress status via API/CLI:
lk egress info EG_xxxxx
which returns
output.download_url
. 3) Correlate Twilio CallSid with LiveKit recording • When using LiveKit, Twilio metadata is available on the SIP participant attributes (e.g.,
sip.twilio.callSid
). Store that attribute to map LiveKit
egress_id
/
download_url
to the Twilio
CallSid
for cross-reference. Which example would you like next: • Full Twilio code sample in your preferred language (Node/Python/cURL)? • Full LiveKit egress API request and a sample
egress_ended
webhook payload? Pick one and I’ll provide the exact snippet.
d
from entrypoint when the call connects, where do i get the callSID? is the participant?
t
Yes — the Twilio CallSid is available on the SIP participant when the call connects. • Attribute name:
sip.twilio.callSid
• Where to read it: the participant's
attributes
(the SIP participant object) once they join the room. Examples: • Node.js:
Copy code
const participant = await ctx.wait_for_participant();
const callSid = participant.attributes['sip.twilio.callSid'];
• Python:
Copy code
participant = await ctx.wait_for_participant()
call_sid = participant.attributes.get('sip.twilio.callSid')
Use that CallSid to correlate with Twilio recordings or logs. Need the exact listener/handler code for your environment? Sources: SIP participant | LiveKit docs
d
ok great... then just make the GET to twilio to get the url. OK I will try. thanks
t
Perfect — glad that helps. If you run into any issues fetching the recording from Twilio or want a quick example in Node/Python/cURL for the GET, tell me which and I’ll send it.