How to create inbound trun and dispatch rule in li...
# ask-ai
m
How to create inbound trun and dispatch rule in livekit self hosted sewrver
t
Thanks for reaching out, Sayed. 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 create an inbound SIP trunk and a dispatch rule on a self‑hosted LiveKit server — I'll guide you step‑by‑step. Quick clarifying question before I give exact commands: do you already have the LiveKit SIP service deployed (Docker Compose or native) and a JWT/API key with SIP admin permissions? If not, tell me which deployment method you prefer (Docker Compose or native) and I’ll provide the exact commands and example requests. Sources: Self-hosted SIP server | LiveKit docs | SIP APIs | LiveKit docs | SIP dispatch rule | LiveKit docs | Inbound calls with Twilio Voice | LiveKit docs | SIP trunk setup | LiveKit docs
m
I install livekit sip with docker in mu google cloud
t
Thanks — since you installed LiveKit SIP with Docker on Google Cloud, I can give exact curl examples and steps for that environment. Quick checks so I can provide the right commands: • Do you have a JWT with SIP‑admin permissions (or API key/secret) ready for authenticating the API calls? • Which phone number(s) should the inbound trunk accept (list E.164 numbers, e.g. +15105550100)? • How do you want incoming calls routed into rooms? Options: ◦ Create a new room per call with a prefix (e.g.,
call-
) ◦ Route to a fixed room name (e.g.,
support-room
) ◦ Route based on the called number or caller (describe mapping) Reply with those answers and I’ll provide the precise curl requests (pointed at your Docker host), example JWT creation notes, and any Google Cloud firewall/port reminders you should check.
m
call- and now allowd number any number can call,
t
Great — I’ll give the exact steps and curl requests to: • create an inbound trunk that accepts calls from any number, and • create a dispatch rule that creates a new room per call with the prefix
call-
. Before you run the examples, confirm these values: • Your LiveKit HTTP(S) endpoint (replace <your-livekit-host>, e.g. https://livekit.example.com or http://34.35.36.37:7880) • A JWT that has SIP-admin permissions (replace <jwt-token>) • The SIP server is reachable on port 5060 and RTP ports 10000–20000 from your SIP provider (Google Cloud firewall and any host firewall must permit these) 1) Create an inbound trunk (accept any number) Use the CreateSIPInboundTrunk API and pass an empty or broad
numbers
list — to accept any number, omit
numbers
(the SIP service will accept calls not matched by specific trunks) or explicitly create a trunk without restricting numbers. Example curl:
Copy code
curl -X POST "<your-livekit-host>/twirp/livekit.SIP/CreateSIPInboundTrunk" \
  -H "Authorization: Bearer <jwt-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "inbound-any",
    "numbers": []
  }'
• Replace
<your-livekit-host>
and
<jwt-token>
. • If the API requires at least one number, provide a broad DID you control; otherwise leaving
numbers
empty makes the trunk act as a catch-all. 2) Create the dispatch rule to create rooms with prefix
call-
Use CreateSIPDispatchRule with a rule that uses
roomPrefix
. Example curl:
Copy code
curl -X POST "<your-livekit-host>/twirp/livekit.SIP/CreateSIPDispatchRule" \
  -H "Authorization: Bearer <jwt-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "dispatch_rule": {
      "rule": {
        "dispatchRuleIndividual": {
          "roomPrefix": "call-"
        }
      },
      "name": "create-room-per-call"
    }
  }'
3) JWT notes • The Authorization header must be a JWT with SIP admin permissions (the SIP APIs require admin-scope credentials). • If you need an example for generating a JWT from your API key/secret, tell me and I’ll provide a snippet for your environment (Node, Go, or curl). 4) Google Cloud / firewall reminders • Open UDP/TCP 5060 (SIP) and UDP 10000–20000 (RTP) on the VM’s external firewall and Google Cloud VPC firewall. • Ensure the Docker container is publishing those ports to the host (check your docker-compose or container port mapping). • If running behind NAT, set
use_external_ip: true
in the SIP config and ensure the external IP is reachable. 5) Verify configuration • Check the trunk list and dispatch rules via the respective API list endpoints (ListSIPInboundTrunks / ListSIPDispatchRules) or via logs from the
livekit-sip
container. • Make a test call from a SIP provider (or softphone) to your SIP URI (sip&lt;your public ip&gt;5060) and confirm a room named like
call-<something>
is created in LiveKit and the call is bridged. • Inspect
livekit-sip
container logs for incoming INVITE handling and dispatch decisions. If you want, I can: • provide a JWT generation example for Node or Go, • show List API calls to confirm the created trunk and rule, • or give exact docker-compose port mappings to verify your setup. Which would you like next?