While doing warm call transfer, I sometimes get th...
# ask-ai
l
While doing warm call transfer, I sometimes get this error: TwirpError(code=deadline_exceeded, message=twirp error unknown: request timed out, status=408)", I am using Twilio. How to go about it
t
Thanks for reaching out, Deepak. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're seeing a SIP transfer timeout (HTTP 408) during warm transfer. I'll walk through the likely causes and focused fixes you can try. Which part I'm answering: warm call transfer failing with
TwirpError(code=deadline_exceeded, message=... request timed out, status=408)
when using Twilio. Key checks and actions 1. Enable SIP REFER / PSTN transfer on your Twilio trunk • Transfers rely on SIP REFER. In the Twilio Console → Elastic SIP Trunking → your trunk → Features → enable Call Transfer (SIP REFER) and Enable PSTN Transfer. Or update via CLI with your trunk SID. 1. Verify the transfer destination is reachable • Confirm the phone number or SIP URI accepts calls and answers. Test calling the destination directly (outside LiveKit) to rule out destination-side issues. 1. Confirm trunk configuration and credentials • Ensure LiveKit is using the correct Twilio SIP domain (e.g., your-trunk.pstn.twilio.com), credentials, and that the trunk allows outbound/transfer calls. 1. Avoid long synchronous waits / handle dialing asynchronously • If you use
wait_until_answered: true
or block while dialing the supervisor, that increases timeout risk. Consider async dialing with status polling and a retry/backoff strategy. 1. Add retries for transient network/provider delays • Implement retry with exponential backoff for transfers — intermittent carrier or network delays often resolve on retry. Diagnostics to gather if this persists • Twilio debugging logs for the trunk: check whether a REFER (or outbound INVITE) was sent and how the destination responded. • Timestamped LiveKit server logs around the transfer attempt. • Exact transfer flow used (CreateSIPParticipant + MoveParticipant vs. TransferSIPParticipant) and any
wait_until_answered
setting. If you’d like, tell me: • Which transfer API call you use (warm transfer flow steps), • Whether you enabled SIP REFER on your trunk, • A recent Twilio debug log excerpt or timestamps — and I’ll suggest the next targeted step. Sources: SIP troubleshooting guide | LiveKit docs | Call forwarding | LiveKit docs | server-sdk-go | livekit/livekit_composite | DeepWiki | Create and configure a Twilio SIP trunk | LiveKit docs | Make outbound calls | LiveKit docs
Thanks — your code snippet confirms you're calling
transfer_sip_participant
with a
tel:
URI, which is the correct structure. I'll focus on the likely causes and the next concrete checks to resolve the Twirp 408 timeout. What I’m answering: why
TwirpError(code=deadline_exceeded, ... status=408)
happens for your
transfer_sip_participant(...)
call and what to verify next. Immediate checks (do these first) • Confirm SIP REFER is enabled on your Twilio trunk: ◦ Twilio Console → Elastic SIP Trunking → your trunk → Features → enable Call Transfer (SIP REFER) and Enable PSTN Transfer. ◦ Or run the CLI update with your trunk SID:
twilio api trunking v1 trunks update --sid <twilio-trunk-sid> --transfer-mode enable-all --transfer-caller-id from-transferee
. • Verify
transfer_to
is E.164 with the + (your
tel:+...
format is correct). Ensure the number is reachable and can accept PSTN calls. • Confirm the participant is still active in
room_name
when you call transfer — a disconnected participant will fail. Additional diagnostics to run • Check Twilio debug logs for the trunk at the transfer timestamp: is a REFER/INVITE sent, and what response or SIP status (if any) is returned? • Inspect LiveKit server logs at the same timestamp for any SIP-related metadata returned by the Twirp error (SIP status code or message). • Try transferring that destination number outside LiveKit (directly via Twilio) to see if the trunk/destination behaves the same. Code-side suggestions • Ensure number normalization to E.164 before calling:
Copy code
transfer_to = f"tel:+{phone_number.lstrip('+')}"
• Add retry with exponential backoff for transient 408s. • Optionally avoid synchronous waiting (e.g.,
wait_until_answered
) to reduce timeout exposure; consider async dialing + status polling. If you run the checks above, share: • Whether SIP REFER/PSTN Transfer are enabled on the trunk, • A Twilio debug log snippet or the trunk-side SIP status returned at the transfer time, • LiveKit log lines around the transfer attempt (timestamps help). With those details I can point to the exact next step. Would you like help parsing the Twilio debug log if you paste the relevant entries? Sources: SIP troubleshooting guide | LiveKit docs | Call forwarding | LiveKit docs | SIP APIs | LiveKit docs
l
On the twilio side, I can see that the call was actually transferred
t
Thanks — since Twilio shows the call was transferred, the 408 is happening after Twilio completes the transfer but before LiveKit receives/acknowledges the final response. I'll help narrow it down. What I'm responding to: your Twilio logs show the transfer succeeded but you're still getting
TwirpError(code=deadline_exceeded, ... status=408)
in LiveKit. Next focused checks • LiveKit server logs: check the exact timestamp of the transfer call and look for Twirp/TCP timeouts, RPC retry attempts, or any SIP-related metadata on the error (e.g.,
sip_status_code
,
sip_status
). Paste the 5–10 log lines around the transfer timestamp if you want help parsing them. • Network latency between LiveKit and Twilio: look for spikes or transient connection resets at the same timestamp (firewall/NAT timeouts, proxy, or packet loss can cause RPC deadline_exceeded). • RPC deadline settings: confirm your client-side call isn’t using an overly short timeout for the Twirp call. If possible, increase the Twirp/RPC deadline for transfers and retry. • Confirm LiveKit processed the downstream event: even if Twilio completed the REFER, LiveKit must receive and process the SIP event. Search LiveKit logs for the participant move/transfer handling after the REFER response. Quick actions to try • Retry the transfer once after a short delay to see if it’s transient. • Temporarily increase the transfer RPC deadline on the client and test again. • Correlate Twilio transfer completion timestamp with the LiveKit log timestamp to see which side lagged. If you can share: • The LiveKit log lines around the transfer timestamp (including any Twirp error stack or metadata), • The RPC timeout/deadline setting you use for
transfer_sip_participant
, I’ll point to the exact field to change or the log entries that indicate whether it’s a network/RPC timeout vs. processing delay. Would you like me to help parse those logs?
l
The RPC timeout/deadline setting you use for
transfer_sip_participant
I haven't provided anything.
t
Thanks — since you didn't set a client-side deadline, the 408 means LiveKit's SIP service timed out waiting for the downstream SIP flow to finish (server-side deadline). Because Twilio shows the call succeeded, focus on these targeted checks: • Confirm SIP REFER & PSTN Transfer are enabled on your Twilio trunk (Console → Elastic SIP Trunking → Trunks → Features → enable Call Transfer (SIP REFER) and Enable PSTN Transfer). • Correlate timestamps: match Twilio's transfer-complete timestamp with LiveKit server logs to see if LiveKit received/processed the final SIP response. Share 5–10 LiveKit log lines around that timestamp if you want help parsing them. • Inspect LiveKit error metadata/logs for any SIP fields (
sip_status_code
,
sip_status
) included with the Twirp error. • Check network latency or connection resets between LiveKit and Twilio at the transfer time (NAT/firewall/proxy timeouts can drop ACKs). • Retry test: attempt the same transfer again; transient provider/network issues sometimes resolve on retry. • As a fallback, test performing the transfer directly via Twilio (outside LiveKit) to verify identical behavior. If you paste the LiveKit log snippet around the transfer timestamp and the Twilio debug lines for the same time, I’ll parse them and point to the exact cause and next fix. Sources: SIP troubleshooting guide | LiveKit docs | Call forwarding | LiveKit docs | Remote method calls | LiveKit docs
l
The twilio and livekit transfer time matches
t
Thanks — since Twilio and LiveKit timestamps match, that rules out simple clock skew or delayed transfer acknowledgements. To find why LiveKit still returns a
deadline_exceeded
(408) even though Twilio completed the transfer, please provide both of the following log excerpts for the same transfer attempt (timestamps must overlap): • 5–10 LiveKit server log lines spanning ~5 seconds before and after the transfer timestamp (include any Twirp error stack or metadata). • The Twilio debug log entries for that transfer (INVITE/REFER/200/ACK or related SIP messages) around the same timestamps. Also tell me: • The participant identity and room_name used (or scrubbed IDs) so I can correlate logs. • Whether you see any
sip_status_code
or
sip_status
fields in the LiveKit error metadata. With those, I’ll parse the SIP transaction flow and point to the exact step that caused the timeout and the concrete fix.
Thanks — I have the room name. To diagnose the timeout I still need a few items you can grab quickly: • 5–10 LiveKit server log lines spanning ~5 seconds before and after the transfer timestamp (include the Twirp error stack/metadata if present). • Twilio debug log entries for the same transfer (INVITE/REFER/200/ACK or related SIP messages) around the same timestamps. • Participant identity used in the transfer (or a scrubbed ID to correlate). • Any
sip_status_code
or
sip_status
fields shown in the LiveKit Twirp error metadata. Also confirm once: SIP REFER and PSTN Transfer are enabled on your Twilio trunk. Send those and I’ll parse the SIP transaction flow and point to the exact cause and next fix.
l
call-log-CAa5d29e6fc2ac224bcfc7ae3cbe516b0b.pcap
t
I noticed your last message was empty. I still need the following to diagnose why LiveKit returns a
deadline_exceeded
(408) even though Twilio shows the transfer completed: • 5–10 LiveKit server log lines spanning ~5 seconds before and after the transfer timestamp (include any Twirp error stack/metadata). • Twilio debug log entries for the same transfer (INVITE/REFER/200/ACK or related SIP messages) around the same timestamps. • Participant identity used in the transfer (or a scrubbed ID to correlate). • Whether
sip_status_code
or
sip_status
appear in the LiveKit error metadata. • Confirm SIP REFER and PSTN Transfer are enabled on your Twilio trunk. If you prefer, paste the LiveKit and Twilio log snippets and I’ll parse them and point to the exact step causing the timeout.