stop the agent trunk for Inbound or outbound ?
# ask-ai
c
stop the agent trunk for Inbound or outbound ?
t
Thanks for reaching out, faiq. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about whether to stop the “agent trunk” for inbound or outbound calls. LiveKit does not have a concept called an “agent trunk.” Trunks in LiveKit are SIP trunks and are managed independently of agents. That means: • Stop the inbound SIP trunk if you want to disable incoming PSTN calls reaching your LiveKit application. This will prevent external callers from joining via phone. • Stop the outbound SIP trunk if you want to disable the ability for participants (including agents) to place calls out to phone numbers. Stopping a trunk affects all call traffic that uses that trunk (including calls involving agents), but it does not stop agent sessions or agent logic themselves. Agents get dispatched to rooms where SIP participants are present; trunks only control the telephony connection into/out of those rooms. Would you like help identifying which trunk is currently handling the calls you want to stop, or instructions for how to stop a specific trunk in your setup? Sources: sip | livekit/livekit_composite | DeepWiki | Agents telephony integration | LiveKit Documentation
c
Example I am creating Inbound and outbound calling system through livekit, now if my users have zero credits (logic on my end) , I want the livekit to not route the calls for both ? whats the best way?
t
Thanks — I’m responding to your question about preventing LiveKit from routing inbound and outbound calls when a user’s credits are zero. Short answer: handle the credit check in your backend and only create the LiveKit SIP objects (dispatch rules for inbound, SIP participants for outbound) when the user has sufficient credits. Trunks are global and don’t know about your credit model, so the safest place to enforce this is before you call LiveKit. Recommended approaches • Inbound calls ◦ Only create a SIP dispatch rule (the rule that routes PSTN calls into rooms/agents) for users who have >0 credits. ◦ If a user’s credits drop to zero, remove or disable their dispatch rule so new incoming PSTN calls no longer get routed to them. ◦ Optionally return a recorded message or IVR response outside LiveKit explaining credits are insufficient (handled by your SIP provider or an IVR front end) rather than letting calls reach LiveKit. • Outbound calls ◦ Before creating a SIP participant or issuing an outbound dial through LiveKit, check the user’s credit balance. ◦ If credits <= 0, reject the call attempt and return an error to the client. ◦ If allowed, deduct expected cost (or reserve credits) before dialing; adjust final billing later using webhooks with actual call duration. Practical implementation notes 1. Centralized credit-check middleware ◦ Implement a single service that authorizes all call-related operations. All endpoints that create dispatch rules or SIP participants call this service first. 1. For inbound: create/remove dispatch rules ◦ Create dispatch rules only when credits are available. ◦ Remove/disable rules immediately when credits reach zero to stop future inbound routing. 1. For outbound: pre-check and reserve ◦ Check credits synchronously before initiating the outbound SIP participant. ◦ Optionally reserve/deduct a minimum cost to avoid mid-call cutoffs; reconcile with actual cost from webhooks after the call. 1. Use LiveKit webhooks ◦ Track call starts/stops and durations via webhooks to finalize credit usage and adjust balances after the call ends. Questions to tailor the recommendation • Do you currently create dispatch rules dynamically per user, or do you have a static routing layer? • For outbound calls, do you prefer reserving credits (to avoid interruption) or deducting post-call based on usage? • Are you using any external SIP provider/IVR in front of LiveKit that could play a “no credits” message? If you share which model you already use (dynamic dispatch vs static routing, and whether you want pre-reservation or post-billing), I can provide example code snippets or a flow diagram for your backend logic. Sources: Agents telephony integration | LiveKit Documentation | Outbound Calling Script | LiveKit Documentation
c
preserve reserving credits, for this we can for outbound just clear out the outbound trunk?
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!