cool-queen-46059
12/06/2025, 11:54 AMtall-airline-16756
12/06/2025, 11:54 AMtall-airline-16756
12/06/2025, 11:55 AMtall-airline-16756
12/06/2025, 11:56 AMsip_trunk_id is an outbound-capable trunk.
• Ensure the access token used has the SIP call grant.
• Use wait_until_answered=True (you already do) and handle errors from create call; if create fails, inspect the exception text for trunk/provider errors.
• Validate participant_identity format (you sanitize — keep E.164 for sip_call_to and sanitized identity for participant_identity).
1. If you intend cold transfer (transfer caller)
• Replace the CreateSIPParticipant flow with a TransferSIPParticipantRequest using the inbound participant identity (the one you see in logs, e.g., sip_18574204454_outbound) and transfer_to="tel:+18574204454". Example flow:
transfer_request = TransferSIPParticipantRequest(
room_name=self.ctx.room.name,
participant_identity=participant_identity, # inbound caller identity
transfer_to=f"tel:{selected_number}",
play_dialtone=True
)
await lkapi.sip.transfer_sip_participant(transfer_request)
1. Quick checks to run now
• Confirm ST_6zVEuhLbud9m is listed as an outbound trunk.
• Confirm provider allows SIP REFER / PSTN transfer.
• Check exact exception message from invite_error (log the full exception) to pinpoint why CreateSIPParticipant failed (trunk/permission/format).
If you tell me whether you want warm vs cold transfer and paste the full exception text from the CreateSIPParticipant failure, I’ll give the exact code change and checks to resolve it.
Sources: Make outbound calls | LiveKit docs | Call forwarding | LiveKit docs | SIP APIs | LiveKit docs | sip | livekit/livekit_composite | DeepWiki | Agent-assisted warm transfer | LiveKit docscool-queen-46059
12/06/2025, 12:02 PMtall-airline-16756
12/06/2025, 12:02 PMcall grant:
{
"sip": {
"call": true
}
}
• Verify sip_trunk_id is an outbound-capable trunk (not inbound-only) and the provider credentials/address are correct (use provider root address, e.g., sip.telnyx.com).
• Confirm the trunk/provider allows outbound dialing and SIP REFER/PSTN transfer if needed.
• Use E.164 for sip_call_to (e.g., +18574204454) and a sanitized identity for participant_identity.
• If you use wait_until_answered=True, be aware of timeouts; try wait_until_answered=False during testing and handle the answered event asynchronously.
• Log and inspect the full exception from CreateSIPParticipant (the stack/HTTP status or provider error) to identify if it’s a trunk auth, DNS/address, or timeout issue.
Implementation notes and LiveKit specifics
• Warm transfer requires a consult room + MoveParticipant to bring the supervisor into the caller’s room. MoveParticipant is a LiveKit Cloud feature (not available on some self-hosted setups).
• Use CreateSIPParticipant only to dial the supervisor into the consultation room (then MoveParticipant). Do not rely on creating an outbound participant in the caller room if your intent is an agent-assisted consult.
• If CreateSIPParticipant continues to fail after the checks above, capture and paste the full exception text (HTTP status, provider error details) and I’ll point to the exact trunk or token fix.
If you want, paste:
• the full exception/stack trace from the CreateSIPParticipant failure, and
• whether you’re on LiveKit Cloud or self-hosted, and your trunk id (confirm outbound capability)
I’ll give the exact code and config changes next.
Sources: SIP APIs | LiveKit docs | Authentication | LiveKit docs | SIP troubleshooting guide | LiveKit docs | Agent-assisted warm transfer | LiveKit docs | Make outbound calls | LiveKit docscool-queen-46059
12/06/2025, 12:06 PMtall-airline-16756
12/06/2025, 12:06 PMtall-airline-16756
12/06/2025, 1:38 PMawait self.ctx.room.sid (AsyncMock). I'll address both and give precise next steps.
1) CreateSIPParticipant still failing — targeted checks
• Log the full exception from the invite_error (HTTP status / provider error). That exact text shows whether it’s trunk auth, DNS/address, or timeout. Please paste it.
• Confirm these three items for your Twilio trunk:
◦ Termination (outbound) configured with a Credential List (username/password) for LiveKit to authenticate when placing outbound calls.
◦ Call Transfer (SIP REFER / PSTN Transfer) enabled in the Twilio trunk settings.
◦ Origination configured so inbound calls reach LiveKit (you said this is enabled).
• Verify the token you use to call create_sip_participant contains the SIP call grant:
{
"sip": {
"call": true
}
}
• Try switching wait_until_answered=True → False while testing to rule out answer-timeout issues. If this makes it succeed, your problem was a timeout while waiting for the supervisor to pick up.
• Ensure sip_trunk_id is the correct outbound trunk id and sip_call_to is E.164 (+18574204454). Keep participant_identity sanitized as you are doing.
• Enable verbose debug/logging on the Twilio trunk side (or check Twilio call logs) to see if Twilio rejects the outbound leg (401 auth, 403, or 404).
2) TypeError: AsyncMock can't be used in 'await' expression
• The traceback shows doc_id=await self.ctx.room.sid — self.ctx.room.sid is an AsyncMock (test/mocking object) rather than an awaitable/sync value. Fix by:
◦ If room.sid is synchronous/string: remove await and use doc_id = self.ctx.room.sid.
◦ If room.sid is a coroutine: await the coroutine (e.g., doc_id = await self.ctx.room.sid()).
• Search your code for other uses of await on attributes that are simple values and remove await there.
3) Minimal repro and immediate actions I can help with
• Please paste:
◦ the full exception text from the CreateSIPParticipant failure (the contents of invite_error).
◦ whether you’re using LiveKit Cloud or self-hosted (MoveParticipant availability matters).
◦ the lines around where you access self.ctx.room.sid (so I can suggest exact code fix).
• While you fetch that, try:
◦ logging the invite exception,
◦ testing CreateSIPParticipant with wait_until_answered=False,
◦ and changing doc_id=await self.ctx.room.sid → doc_id=self.ctx.room.sid (if sid is not async).
If you share the full CreateSIPParticipant exception and the small code snippet around self.ctx.room.sid, I’ll give the exact code edits and the likely trunk/token fix.tall-airline-16756
12/06/2025, 1:39 PMcall grant:
{
"sip": {
"call": true
}
}
2) Trunk termination/auth
• Ensure ST_6zVEuhLbud9m is configured for termination (outbound) with a Credential List (username/password) so Twilio accepts outbound legs from LiveKit.
• Confirm the trunk appears in Twilio’s outbound/termination list and that credentials are valid.
3) sip_call_to & identity format
• Use E.164 for sip_call_to (e.g., +18574204454) and sanitized ASCII for participant_identity (you already sanitize — keep that).
• Set sip_call_to= "+18574204454" (not tel:+...) when passing to CreateSIPParticipant if your SDK expects plain E.164; if it expects tel:, use tel:+1857... — check which your LiveKit SDK variant expects.
4) wait_until_answered
• For debugging, set wait_until_answered=False to avoid timeouts. If this makes the call succeed, the failure was an answer timeout. Then you can handle answer events instead.
5) Inspect and paste the full invite exception
• In your except block, log the full exception including HTTP status/body:
except Exception as invite_error:
logger.exception("CreateSIPParticipantRequest failed")
• Paste that full logged traceback/HTTP body here — it will show if Twilio returned 401/403/404 or a timeout.
6) Twilio-side debug
• Check Twilio trunk call logs for the attempted outbound leg at the same timestamp — Twilio will show if it rejected the request (auth/DNS/403/etc.) or if it never received it.
7) Quick runtime checks
• Confirm you’re calling participant = await lkapi.sip.create_sip_participant(invite_request) with the API client authenticated by a token that has SIP grants and not a mocked/test token.
• Ensure DNS for your configured trunk address is reachable from your LiveKit server.
If you run the request with wait_until_answered=False and then paste the full exception/traceback you get when it still fails (or the Twilio call-log error code), I’ll pinpoint the exact fix.cool-queen-46059
12/06/2025, 1:41 PMtall-airline-16756
12/06/2025, 1:42 PMsip_call_to (e.g., +18574204454 or tel:+18574204454)?
• Does the API client used for create_sip_participant use an access token that includes "sip": {"call": true}?
With the full exception and these confirmations I’ll pinpoint whether it’s a trunk auth/DNS/timeout issue or a request-format/token problem and give the exact code/config change.cool-queen-46059
12/06/2025, 1:42 PMtall-airline-16756
12/06/2025, 1:42 PMcall grant when you generate the LiveKit access token on your backend. Examples:
Python (server):
from livekit import api
token = (
api.AccessToken(api_key="API_KEY", api_secret="API_SECRET")
.with_identity("transfer-agent")
.with_grants(api.VideoGrants(room_join=True, room="my-room"))
.with_sip_grants(api.SIPGrants(admin=False, call=True)) # <-- call=True here
.to_jwt()
)
Node.js:
import { AccessToken, SIPGrant, VideoGrant } from "livekit-server-sdk";
const at = new AccessToken("apiKey", "secret", { identity: "transfer-agent" });
at.addGrant({ roomJoin: true, room: "my-room" }); // video grant
at.addGrant(new SIPGrant({ admin: false, call: true })); // <-- call: true
const jwt = at.toJwt();
Go:
at := auth.NewAccessToken("apiKey","secret")
at.SetIdentity("transfer-agent").
SetVideoGrant(&auth.VideoGrant{RoomJoin:true, Room:"my-room"}).
SetSIPGrant(&auth.SIPGrant{Admin:false, Call:true}) // <-- Call:true
token, _ := at.ToJWT()
Key points:
• Generate the token server-side (never in client code).
• The sip.call = true grant must be present for CreateSIPParticipant to allow outbound calls.
• Use that token when calling create_sip_participant.
• After adding the grant, if CreateSIPParticipant still fails, paste the full exception/log (HTTP status and body) and I’ll help diagnose further. Sources: Authentication | LiveKit docs | sip | livekit/livekit_composite | DeepWikicool-queen-46059
12/06/2025, 2:10 PMtall-airline-16756
12/06/2025, 2:10 PMparticipant_identity (or participantIdentity depending on SDK), not identity.
What to change (Python example)
from livekit import api
invite_req = api.CreateSIPParticipantRequest(
sip_trunk_id="ST_6zVEuhLbud9m",
sip_call_to="+18574204454",
room_name="mock_room",
participant_identity="sip_18574204454_transfer", # <-- correct key
wait_until_answered=True,
)
await lkapi.sip.create_sip_participant(invite_req)
Quick checklist to verify after fixing the field
• Token includes sip.call = true (server-side token).
• sip_trunk_id is outbound-capable and valid.
• sip_call_to is E.164 (+18574204454) or uses tel: only if your SDK requires it.
• Log the full exception if it still fails (use logger.exception(...)) so I can see HTTP status/body.
If you paste the snippet where you build the CreateSIPParticipantRequest (or the full traceback after switching the field), I’ll point out the exact line to change.