create_sip_participant offers two different timeou...
# ask-ai
i
create_sip_participant offers two different timeout arguments, how should they be used together?
t
Thanks for reaching out, Ed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Let me help clarify the two timeout arguments in
create_sip_participant
for you: •
ringingTimeout
: This sets the maximum time the callee has to answer the call before it ends. Think of it as a SIP-level timeout, with a maximum limit of 80 seconds. •
timeout
: This controls how long your client waits for a response from the LiveKit server when creating the SIP participant. It’s an RPC-level timeout. How these two work together depends on the
waitUntilAnswered
flag: • When
waitUntilAnswered = true
: The API call will wait (or block) until the callee either answers or the call fails. To avoid the call being cancelled too soon, make sure your
timeout
is set higher than
ringingTimeout
. • When
waitUntilAnswered = false
: The API call returns right after starting the call. Here,
timeout
only needs to cover the call initiation, while
ringingTimeout
independently manages how long the phone rings. Feel free to adjust these values based on what fits your situation best, so you get the right balance between call behavior and API response timing. If you have any questions or need further guidance, I’m here to help! Sources: packages/livekit-server-sdk/src/SipClient.ts | pkg/service/sip.go | cmd/lk/sip.go | protobufs/livekit_sip.proto | Docs::Telephony
i
i see, currently i have timeout as shorter than ringingTimeout, because timeout, when it expires, will return an asyncio TimeoutError and it’s easily to programmatically tell that this was a timeout. ringingTimeout on the other hand returns a twirp error which it will also return if for whatever reason the process is interrupted, so it’s hard to differentiate between a timeout and request interruption
t
Thank you for reaching out with your question about distinguishing between
asyncio.TimeoutError
and
TwirpError
. Let’s walk through this together: •
asyncio.TimeoutError
: This happens when the client doesn’t get a response from the LiveKit server within the set
timeout
. It’s a client-side issue and usually points to a network or server delay. You can handle this in your code to manage such delays gracefully. •
TwirpError
: This is a server-side error that carries SIP-specific details like
sip_status_code
and
sip_status
. For instance, a SIP 408 error means the callee didn’t answer within the
ringingTimeout
. Here are a couple of tips to help you improve your error handling: • Make sure your
timeout
is set longer than
ringingTimeout
so your client waits sufficiently for the SIP process to finish. • Take a close look at the
TwirpError
metadata to tell apart a timeout (like SIP 408) from other issues. For example:
Copy code
except api.TwirpError as e:
    sip_code = e.metadata.get('sip_status_code')
    if sip_code == '408':
        print("Call failed: Remote party did not answer within ringingTimeout.")
    else:
        print(f"SIP error: {sip_code} {e.metadata.get('sip_status')}")
By syncing your
timeout
and
ringingTimeout
settings and using the error metadata, you’ll be able to clearly distinguish between these cases and handle them smoothly in your application. If you have any more questions or need further help, I’m here for you! Sources: cmd/lk/sip.go | packages/livekit-server-sdk/src/SipClient.ts | agent.py | Agents telephony integration | LiveKit Docs | livekit-rtc/livekit/rtc/participant.py
i
but i dont get a 408 when ringingTimeout expires, i get a "twirp error unknown: canceled"
t
I understand that encountering the "twirp error unknown: canceled" can be a bit confusing. This happens because when the
ringingTimeout
runs out, the Go context for the SIP call gets canceled, and this cancellation shows up as a Twirp "Canceled" error. It’s important to know that this process skips the usual SIP-level status code mapping (like SIP 408) which is used internally but doesn’t appear in the final API response. To help you manage this smoothly, here are some friendly tips: • Make sure to explicitly catch and handle the Twirp "Canceled" error in your client code. • Use
lksdk.SIPStatusFrom(err)
to pull out SIP-specific details (such as
SIPStatusCode
and
SIPStatus
) from the error object—this can give you clearer insights when diagnosing issues. • Check that your
ringingTimeout
is set to a sensible value that fits typical call setup times (the default is 3 minutes). • If you want to avoid long waits on the client side, consider setting
WaitUntilAnswered=false
for asynchronous behavior. Following these steps should make it easier to tell the difference between a timeout and other interruptions, helping you keep your error handling clear and effective. If you have any more questions or need further assistance, I’m here to help! Sources: pkg/sip/protocol.go | livekit/livekit_sip.twirp.go | cmd/lk/sip.go
i
i thought the default timeout was 80 seconds?
t
Thanks for your question! The default timeout for
create_sip_participant
actually depends on the SDK you're using and the
wait_until_answered
flag: • For the Go server, the default timeout is 30 seconds if
WaitUntilAnswered
is
false
, and it extends to 80 seconds when
WaitUntilAnswered
is
true
. • In the Node.js SDK, you'll find the default is 60 seconds when
waitUntilAnswered
is
true
, and a shorter 10 seconds otherwise. • With the Python SDK, the timeout defaults to 20 seconds if
wait_until_answered
is
true
, but this applies only if your client’s configured timeout is less than 20 seconds. These timeouts vary across SDKs and tend to be longer when waiting for the call to be answered. If you'd like, I’m here to help you adjust these settings to perfectly fit your needs—just let me know! Sources: packages/livekit-server-sdk/src/SipClient.ts | cmd/lk/sip.go | pkg/service/sip.go | livekit-protocol/livekit/protocol/sip.pyi
i
im using the python sdk with
wait_until_answered
= True. so the ringingTimeout needs to be shorter than the client timeout?
t
Absolutely! When you're using the Python SDK with
wait_until_answered=True
, it's important that the
ringingTimeout
is set to a value shorter than the client
timeout
. This helps make sure your SIP call has enough time to connect within the client’s waiting period. For instance, if your
ringingTimeout
is 30 seconds, I’d recommend setting the client
timeout
to around 35–40 seconds. This little buffer allows for any extra processing time and helps avoid the client timing out too soon while the call is still ringing. If you’d like, I’m here to help you fine-tune these settings or answer any other questions you might have!
i
you'll never receive the asyncio.TimeoutError in that case would you?
t
You're absolutely right! If the
ringingTimeout
is set shorter than the client
timeout
, you typically won't see an
asyncio.TimeoutError
unless there's a network hiccup or the server stops responding. Instead, when the
ringingTimeout
runs out, the server will cancel the SIP call and return a Twirp "Canceled" error, just like we talked about earlier. This setup helps keep things clear: the client timeout covers the whole API call duration, while the
ringingTimeout
specifically manages the SIP call timing. If you'd like, I'm here to help with any more questions or to walk you through error handling strategies. Just let me know!
i
how can i differentiate between a request timeout and a request interruption?
t
I understand how important it is to clearly distinguish between a request timeout and a request interruption when working with the Python SDK. To help with this, you can take a look at the error metadata that comes with the Twirp error. A handy way to do this is by using
lksdk.SIPStatusFrom(err)
, which lets you pull out SIP-specific details like
SIPStatusCode
and
SIPStatus
. Here’s a simple example to guide you:
Copy code
try:
    participant = await livekit_api.sip.create_sip_participant(request, timeout=45)
except api.TwirpError as e:
    sip_code = e.metadata.get('sip_status_code')
    sip_message = e.metadata.get('sip_status')

    if sip_code == '408':
        print("Request timeout: The callee did not answer within the ringingTimeout.")
    elif sip_code:
        print(f"Request interruption: SIP error {sip_code} - {sip_message}")
    else:
        print(f"Unknown error: {e.message}")
By checking the
SIPStatusCode
, you’ll be able to tell if the issue was a timeout (like SIP 408) or some other kind of interruption, such as network troubles or call rejection. If you have any questions or want to explore this further, feel free to ask—I’m here to help!
i
but a requestTimeout doesnt provide a 408 error
t
You're absolutely right that a request timeout doesn't always come with a SIP 408 error. When you don't see a SIP 408, it's likely that the timeout happened at the RPC or HTTP client level, rather than within the SIP signaling itself. To help you tell the difference between a request timeout and a request interruption here: • If the error includes SIP metadata (like
SIPStatusCode
or
SIPStatus
), that usually means it's a SIP-level issue. For instance, a SIP 403 or 404 would suggest the call was rejected or the number was invalid. • If there’s no SIP metadata and the error relates to the RPC or HTTP layer (such as "deadline exceeded" or "context canceled"), it’s probably a transport-level timeout or interruption. To dig a bit deeper, you might want to: • Look at the error response for SIP-specific details using
lksdk.SIPStatusFrom(err)
. • Double-check your timeout settings for
wait_until_answered
and the client-side
timeout
to make sure they’re in sync. • Keep an eye on participant events (like
sip.callStatus
) to see how the call is progressing after it starts. Please feel free to reach out if you'd like a hand with these checks or need help tweaking your setup—I’m here to support you! Sources: livekit-api/livekit/api/sip_service.py | packages/livekit-server-sdk/src/SipClient.ts | Docs::Agents | livekit/livekit_sip.pb.go | cmd/lk/sip.go
i
a "twirp error canceled" error could refer to either a request timeout or a request interruption right? is there a way to differentiate between the two
t
Hi there! A "twirp error canceled" can indeed mean either a request timeout or a request interruption. To help you figure out which one it is, you can take a closer look at the context and metadata of the error: • Request Timeout: This usually happens when the client or server exceeds a set deadline. You might find messages like "deadline exceeded" or other timeout-related notes in your logs or error metadata. • Request Interruption: This occurs when the process is intentionally canceled—maybe by the user or due to a network hiccup. In this case, the error might not mention timeouts but will indicate a cancellation event. To pinpoint the cause programmatically, you can: • Check the error metadata for extra details such as
SIPStatusCode
or
SIPStatus
, if they’re available. • Review the error context in your logs to see if it was triggered by a timeout or an explicit cancellation. • Double-check that your
timeout
and
ringingTimeout
settings are properly configured to prevent any premature cancellations. If you'd like, I’m here to help you walk through these steps or troubleshoot any specific situations you’re facing. Just let me know!