Deploy LiveKit Voice Agent — Self-Hosted WebRTC AI on Railway
Self-host LiveKit: OpenAI voice agent with WebRTC. No per-minute fees.
Voice Agent
Just deployed
LiveKit Server
Just deployed
web-frontend
Just deployed
Redis
Just deployed
/data
Deploy and Host LiveKit Voice Agent on Railway
LiveKit is the open-source WebRTC infrastructure behind OpenAI's ChatGPT voice mode — 12k+ GitHub stars, $100M raised, $1B valuation, and the most widely used real-time voice AI platform in production. This template deploys a complete self-hosted LiveKit stack: voice agent, media server, Redis coordinator, and web frontend — pre-wired on Railway with TCP-mode WebRTC configured out of the box.
Build a conversational AI voice agent powered by OpenAI Whisper, GPT-4o, and TTS — or swap to the Realtime API for sub-500ms speech-to-speech latency. One API key. No WebRTC infrastructure expertise required.
What This Template Deploys
| Service | Purpose |
|---|---|
| Voice Agent | Python-based AI agent — runs the STT → LLM → TTS pipeline or OpenAI Realtime API depending on AGENT_MODE; handles session lifecycle and participant events |
| LiveKit Server | Open-source WebRTC media server — manages room state, participant connections, and media routing via TCP proxy on port 7882 |
| Web Frontend | Browser-based voice UI — connects participants to the LiveKit room and streams real-time transcripts for both user and agent |
| Redis 8.2.1 | Room state coordination and agent job dispatch — required by LiveKit server for multi-room and multi-agent support |
All four services are pre-wired over Railway's private network. TCP-mode WebRTC is pre-configured via iptables — no UDP port setup, no TURN/STUN server configuration required.
About Hosting LiveKit
Running LiveKit in production requires coordinating a WebRTC media server, a Redis instance for room state, backend agent workers for AI pipeline processing, and a frontend that connects over WebRTC — all behind proper TLS with ICE transport configured for your network environment. Most cloud platforms require manual UDP port forwarding, TURN server setup, and firewall rules just to get a WebRTC connection established.
Railway does not support UDP natively — this template pre-configures a TCP proxy at port
7882 with automatic iptables forwarding so WebRTC ICE transport works without any network
configuration on your part.
Typical cost: ~$10–20/month on Railway's Hobby plan. LiveKit Cloud charges $0.01–$0.02 per participant minute — at 1,000 minutes that's $10–20 in per-minute billing before agent compute costs.
Deploy in Under 5 Minutes
- Click Deploy on Railway — all four services build automatically (~4–6 minutes)
- Set
OPENAI_API_KEYin the Variables tab — the only required variable - Optionally set
AGENT_MODEtorealtimefor OpenAI Realtime API (lower latency) or leave blank for the defaultpipelinemode (Whisper + GPT-4o-mini + TTS-1) - Open your Railway-assigned frontend URL — click Connect to start a voice session
- Speak to your agent and watch real-time transcripts appear for both sides
No UDP configuration. No TURN server setup. No WebRTC expertise required.
Common Use Cases
- Self-hosted alternative to LiveKit Cloud — run the same open-source stack that powers LiveKit Cloud on your own Railway infrastructure; no per-participant-minute billing
- Self-hosted alternative to Bland.ai and Vapi.ai — build AI voice agents without $0.05–$0.10/minute voice API fees; bring your own OpenAI key and pay only for tokens
- Conversational AI voice assistant — deploy a GPT-4o-powered voice agent that listens, understands, and responds in natural speech with real-time transcript visibility
- OpenAI Realtime API voice demo — prototype speech-to-speech AI interactions with
sub-500ms latency using the
realtimeagent mode before committing to managed infrastructure - Voice AI prototype without infrastructure overhead — validate conversational AI voice ideas on self-hosted WebRTC before moving to a production-scale deployment
- Custom STT/LLM/TTS pipeline — swap OpenAI components for Deepgram (STT), any LLM via OpenRouter, or Cartesia (TTS) using LiveKit Agents' plugin ecosystem
Configuration
| Variable | Required | Description |
|---|---|---|
OPENAI_API_KEY | ✅ Required | Powers Whisper STT, GPT-4o-mini LLM, and TTS-1 — the only variable needed at deploy time |
AGENT_MODE | Optional | pipeline (default) — Whisper → GPT-4o-mini → TTS-1. realtime — OpenAI Realtime API, lower latency speech-to-speech |
LIVEKIT_URL | Auto-configured | WebSocket URL for the LiveKit server — auto-set to the Railway internal service URL |
LIVEKIT_API_KEY | Auto-generated | LiveKit server API key — generated at deploy time, shared across services |
LIVEKIT_API_SECRET | Auto-generated | LiveKit server API secret — generated at deploy time, shared across services |
REDIS_URL | Auto-injected | Redis connection URI — injected from the Railway Redis service |
The LiveKit server runs in TCP-only mode via Railway's TCP proxy at port
7882. The entrypoint script configures iptables port forwarding automatically — do not change the TCP proxy port assignment in Railway service settings.
LiveKit vs. Managed Voice AI Platforms
| LiveKit (self-hosted) | LiveKit Cloud | Bland.ai | Vapi.ai | |
|---|---|---|---|---|
| Pricing model | Flat compute (~$10–20/mo) | $0.01–$0.02/min | ~$0.05–$0.10/min | ~$0.05/min |
| 1,000 min/month cost | ~$10–20 flat | $10–20 | $50–100 | ~$50 |
| Self-hostable | ✅ Yes | ❌ No | ❌ No | ❌ No |
| Open source | ✅ Yes | ❌ No | ❌ No | ❌ No |
| BYO LLM/STT/TTS | ✅ Full control | ⚠️ Limited | ❌ Fixed | ⚠️ Limited |
| Realtime API support | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
| Data ownership | ✅ Your infra | ❌ LiveKit servers | ❌ Bland servers | ❌ Vapi servers |
| MCP tool support | ✅ Native | ⚠️ Limited | ❌ No | ❌ No |
Dependencies for LiveKit Hosting
- OpenAI API key — powers STT (Whisper), LLM (GPT-4o-mini), and TTS (TTS-1) by default
- Railway account — Hobby plan (~$10–20/month) covers all four services
- Optional: Deepgram API key for alternative STT, Cartesia for alternative TTS, OpenRouter for alternative LLM — all supported via LiveKit Agents plugin system
Deployment Dependencies
- LiveKit Server GitHub — open-source WebRTC media server
- LiveKit Agents Framework — Python agent pipeline SDK
- LiveKit Documentation — full configuration reference
- OpenAI API Keys — STT, LLM, and TTS provider
- LiveKit Agents Plugins — Deepgram, Cartesia, ElevenLabs, and other STT/TTS integration guides
Implementation Details
LIVEKIT_API_KEY and LIVEKIT_API_SECRET are auto-generated at deploy time and shared across
all services via Railway reference variables. Redis runs on redis:8.2.1 with a persistent
/data volume. The entrypoint script configures iptables to forward ICE traffic through the
TCP proxy at port 7882 with haproxy fallback — no manual firewall setup required.
Agent modes via AGENT_MODE:
pipeline(default): Whisper STT → GPT-4o-mini → TTS-1realtime: OpenAI Realtime API, sub-500ms speech-to-speech
Frequently Asked Questions
How does LiveKit compare to Bland.ai or Vapi.ai for voice AI? Bland.ai and Vapi.ai are managed voice AI platforms charging $0.05–$0.10 per minute. At 1,000 minutes/month that's $50–100 in API costs before any LLM token charges. LiveKit self-hosted on Railway runs at ~$10–20/month flat for the full stack — you pay only Railway compute and your OpenAI token usage. You also get full control over STT, LLM, and TTS providers.
Why does this template use TCP instead of UDP for WebRTC?
Railway's platform does not expose raw UDP ports. This template pre-configures LiveKit to use
TCP transport via Railway's TCP proxy at port 7882, with iptables forwarding handled
automatically at startup. Latency is marginally higher than UDP but fully functional for voice
agent use cases.
What is the difference between pipeline and realtime agent modes?
pipeline mode chains OpenAI Whisper (STT) → GPT-4o-mini (LLM) → TTS-1 (speech) — three
sequential API calls per turn, ~1–3 second round-trip latency. realtime mode uses OpenAI's
Realtime API for end-to-end speech-to-speech processing, achieving sub-500ms latency. Realtime
mode costs more per session but delivers a significantly more natural conversational experience.
Can I swap OpenAI for a different STT, LLM, or TTS provider? Yes. LiveKit Agents has a plugin ecosystem supporting Deepgram (STT), ElevenLabs and Cartesia (TTS), and any LLM via OpenRouter or direct API. Swap plugins in the agent code and add the relevant API key in Railway Variables.
Do I lose room state or conversation history if Railway redeploys?
Room state is stored in Redis, which has a persistent /data volume — active room state
survives container restarts. Conversation history handling depends on your agent implementation.
The LiveKit server and voice agent are stateless beyond what Redis holds.
How much does it cost to run LiveKit on Railway? Approximately $10–20/month on Railway's Hobby plan for all four services. OpenAI API costs are additional — GPT-4o-mini at $0.15/1M input tokens keeps LLM costs low for typical voice sessions. Compare to LiveKit Cloud at $0.01–$0.02 per participant minute or Vapi.ai at $0.05/min.
Why Deploy LiveKit on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying LiveKit on Railway, you get the same open-source WebRTC infrastructure that powers ChatGPT's voice mode — self-hosted, with full STT/LLM/TTS provider control, no per-minute billing, and zero WebRTC networking expertise required.
Template Content
Voice Agent
sahilrupani/LiveKit-TemplateOPENAI_API_KEY
Your OpenAI API key
LiveKit Server
sahilrupani/LiveKit-Templateweb-frontend
sahilrupani/LiveKit-TemplateRedis
redis:8.2.1