how self host livekit sip server ?
# ask-ai
p
how self host livekit sip server ?
t
Thanks for reaching out, arpan. 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 how to self‑host LiveKit’s SIP functionality. Short answer: You run the SIP service as part of a self‑hosted LiveKit server (the SIP bridge is integrated into the main LiveKit server; it cannot be deployed as a separate standalone process). To enable SIP you deploy LiveKit and enable/configure the SIP options. To get you started, do the following: 1. Deploy the LiveKit server using one of these methods: ◦ single Go binary ◦ Docker ◦ Kubernetes with the livekit Helm chart ◦ VM (e.g., EC2 with cloud-init) 1. Enable SIP in the server configuration (SIP is an integrated server feature that bridges PSTN/SIP to rooms). 2. Configure networking and TLS: ◦ Ensure your domain has a valid SSL cert. ◦ Open required ports (e.g., 443 plus LiveKit signaling/media ports). 1. Configure SIP trunks and routing: ◦ Add inbound/outbound SIP trunks from your SIP provider. ◦ Create dispatch rules to route incoming calls to specific LiveKit rooms. ◦ Manage SIP resources programmatically via server‑side SDKs or API (use JWT tokens with appropriate SIP grants like
admin
or
call
). If you want, tell me: • Which deployment method you prefer (Docker, Helm/K8s, VM, or binary), and • Whether you already have a SIP provider or a phone trunk to connect, and I’ll give step‑by‑step configuration details for that setup. Sources: sip | livekit/livekit_composite | DeepWiki | livekit/livekit_composite | DeepWiki | Server-side | livekit/livekit_composite | DeepWiki | Running LiveKit on AWS
p
VM deployment phone number from twilo
t
Thanks — I’m following up on your goal: deploy LiveKit on a VM and use a Twilio phone number (Twilio SIP) for PSTN connectivity. A few quick clarifying questions so I can give exact step‑by‑step commands: 1. Which VM OS will you use (Ubuntu/Debian/CentOS/etc.)? 2. Do you already have a Twilio phone number and SIP trunk set up, or do you need steps for provisioning them? 3. Do you want a simple single‑server test setup or a production setup (with Kubernetes/HA, certificates, firewall rules)? Once you tell me the answers above I’ll provide a focused VM deployment checklist and the exact LiveKit + Twilio configuration steps (including required ports, TLS, JWT grants, Twilio SIP trunk settings, and example dispatch rules).
p
Ubuntu
t
Great — you’re on Ubuntu and want to use a Twilio phone number. I’ll give a focused VM checklist and step‑by‑step commands to deploy LiveKit (Docker) with SIP enabled and connect Twilio. Before we start, quick confirmation: • Do you already have a Twilio phone number and SIP Trunk (or Elastic SIP Trunk) provisioned and credentials (SIP URI or trunk domain, auth username/password or IP ACL)? • Do you want a simple single‑VM test setup or a hardened production VM (TLS via LetsEncrypt, firewall rules)? If you confirm those two, I’ll provide the exact Ubuntu commands, a Docker Compose example with SIP settings, TLS notes, firewall/ports to open, and example Twilio trunk/voice webhook/dispatch rule settings.
p
Do you already have a Twilio phone number and SIP Trunk yes simple single‑VM test setup
yes
t
Thanks — I’ll walk you through a simple single‑VM Ubuntu test setup that runs LiveKit in Docker, enables the integrated SIP bridge, and connects your Twilio phone number/trunk. If anything below is unclear, tell me which step and I’ll expand with exact example files or commands. Prerequisites (you have): • Ubuntu VM (18.04/20.04/22.04) • Twilio phone number and an Elastic SIP Trunk (or SIP Domain) with credentials or IP ACL ready • A domain name pointing to your VM (needed for TLS / TURN; you can use self‑signed for tests but TLS is recommended) Step 1 — Install Docker & Docker Compose 1. Update and install packages: sudo apt update && sudo apt upgrade -y sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release 1. Install Docker: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt update sudo apt install -y docker-ce docker-ce-cli containerd.io sudo usermod -aG docker $USER newgrp docker 1. Install Docker Compose (plugin or v2): sudo apt install -y docker-compose-plugin (You can also install docker-compose v1 if preferred.) Step 2 — Create a directory for LiveKit and config mkdir ~/livekit && cd ~/livekit Step 3 — Generate API keys / secrets for LiveKit Create a small config file or set env vars for LiveKit API key and secret. Example env file `.env`: LIVEKIT_API_KEY=examplekey LIVEKIT_API_SECRET=examplesecret LIVEKIT_DOMAIN=your.domain.example Use strong random values for keys in tests. Step 4 — Docker Compose with SIP enabled Create
docker-compose.yml
(below is a minimal example). Replace domain, keys, and adjust ports if needed.
Copy code
version: "3.8"
services:
  livekit:
    image: <http://ghcr.io/livekit/livekit:latest|ghcr.io/livekit/livekit:latest>
    restart: unless-stopped
    environment:
      - LIVEKIT_API_KEY=${LIVEKIT_API_KEY}
      - LIVEKIT_API_SECRET=${LIVEKIT_API_SECRET}
      - LIVEKIT_DOMAIN=${LIVEKIT_DOMAIN}
      - LIVEKIT_TLS_CERT=/certs/fullchain.pem
      - LIVEKIT_TLS_KEY=/certs/privkey.pem
      - LIVEKIT_SIP_ENABLED=true
      - LIVEKIT_SIP_BIND_ADDR=0.0.0.0:5060
      # Optional: SIP TLS port
      - LIVEKIT_SIP_TLS_ENABLED=false
      # Add TURN config if you have one
    ports:
      - "443:443"
      - "7880:7880"
      - "7881:7881"
      - "7882:7882/udp"
      - "5060:5060"    # SIP UDP/TCP (basic testing)
      - "5061:5061"    # optional SIP TLS
    volumes:
      - ./certs:/certs:ro
Notes: •
LIVEKIT_SIP_ENABLED=true
turns on the integrated SIP bridge. •
LIVEKIT_SIP_BIND_ADDR
sets the SIP listening address/port. Twilio often uses 5060/5061. • For production, run SIP over TLS (5061) and require secure credentials. Step 5 — TLS certificates • For tests you can place cert files at
./certs/fullchain.pem
and
./certs/privkey.pem
(from Let’s Encrypt or self‑signed). • For Let’s Encrypt on a single VM you can use certbot: sudo snap install core; sudo snap refresh core sudo snap install --classic certbot sudo certbot certonly --standalone -d your.domain.example Then copy certs to
./certs
(fullchain.pem and privkey.pem). Step 6 — Configure Twilio SIP trunk Option A — Twilio Elastic SIP Trunk (recommended) • In Twilio Console → Elastic SIP Trunking → Create a Trunk. • Add a SIP URI or Origination URI that points to your VM domain/IP and port (e.g., sipyour.domain.example5060). • Under Origination -> Add Primary Trunk Termination: set your server IP or domain, port 5060 (or 5061 for TLS). • Configure Authentication: if using IP ACL, add your VM public IP to the Trunk’s Origination IP Access Control List. If using credential lists, create username/password and use SIP URI auth on LiveKit (see next). Option B — Twilio SIP Domain (SIP Interface) • Use a SIP Domain and configure Voice -> SIP Trunks to point to your LiveKit SIP endpoint. Step 7 — LiveKit SIP routing / dispatch rules • LiveKit routes incoming SIP calls into rooms using dispatch rules. For a simple test you can configure a default rule that maps any incoming DID to a room name. Example: Use a small script or API call creating a SIP dispatch rule that maps incoming calls for a phone number to a room. You will call LiveKit server admin endpoints with a JWT that has SIP admin/grants. Minimal programmatic flow: 1. Create an admin JWT with
admin
or
call
SIP grant using your `LIVEKIT_API_KEY`/`LIVEKIT_API_SECRET`. 2. POST to the LiveKit SIP API endpoint to create a SIP resource or dispatch rule linking the inbound SIP URI (or phone number) to a room. If you want, I’ll give a concrete curl example to create a dispatch rule — tell me if you prefer
curl
, Python, or Node. Step 8 — Firewall / Ports Open ports on your VM: • 443 TCP (signaling / HTTPS) • 7880-7882 (LiveKit internal ports used in many setups) • 5060 TCP/UDP and/or 5061 TCP (SIP) • UDP ephemeral ports for media (LiveKit/ICE will negotiate; ensure UDP is allowed) Example ufw commands: sudo ufw allow 22/tcp sudo ufw allow 443/tcp sudo ufw allow 5060/tcp sudo ufw allow 5060/udp sudo ufw allow 5061/tcp sudo ufw enable Step 9 — Start LiveKit docker compose up -d Check logs: docker compose logs -f livekit Watch for SIP binding messages and successful certificate usage. Step 10 — Test an inbound call • From Twilio, configure an Origination/Voice webhook to point to your trunk. • Place a call to your Twilio number. The SIP INVITE should arrive at your LiveKit SIP bind address and, if dispatch rules are set, join the specified room. If you want sample JWT creation and a curl example to create a dispatch rule or SIP resource, tell me whether you want Node, Python, or curl and I’ll provide exact commands and sample payloads. Summary — what I can provide next: • Exact
docker-compose.yml
completed with your domain and keys • Certbot commands and how to place certs into the container • Example admin JWT creation and
curl
request to create a SIP dispatch rule • Example Twilio trunk settings (origination URI and IP ACL entries) Which of the above would you like me to produce now?