VoiceGateway // DOCS

Architecture Overview

VoiceGateway is cost tracking and reconciliation for LiveKit voice agents. It returns native LiveKit STT, LLM, and TTS plugin instances across cloud providers and local models, with modality-aware uni

Architecture Overview

VoiceGateway is cost tracking and reconciliation for LiveKit voice agents. It returns native LiveKit STT, LLM, and TTS plugin instances across cloud providers and local models, with modality-aware unit accounting (audio-minutes, tokens, characters), resolver-time fallback chains, rate limiting, budget enforcement, a voicegw reconcile command, and a web dashboard.

System Architecture

User Code / LiveKit Agent Core Layer Middleware Pipeline Provider Layer Storage Layer External Interfaces gateway.stt('deepgram/nova-3') gateway.llm('openai/gpt-4.1-mini') gateway.tts('cartesia/sonic-3') Gateway Router Registry ModelId Parser BudgetEnforcer InstrumentedProvider CostTracker LatencyMonitor RateLimiter FallbackChain RequestLogger BaseProvider ABC OpenAI Deepgram Cartesia Anthropic Groq ElevenLabs AssemblyAI Ollama Whisper Kokoro Piper SQLite ConfigManager Crypto / Fernet FastAPI HTTP Server Dashboard - React/Vite MCP Server CLI - voicegw

Request Flow

Every call to gateway.stt(), gateway.llm(), or gateway.tts() follows the same path:

gateway.stt("deepgram/nova-3", project="prod") check_budget("prod") get_cost_summary("today", project="prod") $4.20 / $10.00 budget OK (under budget) resolve("deepgram/nova-3", "stt") parse("deepgram/nova-3") ModelId(provider="deepgram", model="nova-3") create_provider("deepgram", config) DeepgramProvider instance create_stt(model="nova-3") STT instance STT instance wrap_provider(instance, "stt", ...) InstrumentedSTT wrapper InstrumentedSTT (proxies all access) create_record(...) log_request(record) On first byte/completion, records TTFB + latency User Code Gateway BudgetEnforcer Router ModelId Registry Provider InstrumentedProvider CostTracker SQLite

Directory Structure

The Python package lives under voicegateway/. A separate dashboard/ tree carries the FastAPI backend and the React + TypeScript + Vite + Recharts frontend for the local cost dashboard.

gateway.py
config.py
config_manager.py
registry.py
schema.py
crypto.py
server.py

Design Principles

  1. Async throughout -- all database, HTTP, and provider operations use async/await. The Gateway provides synchronous wrapper methods for convenience.

  2. Lazy loading -- providers are only imported and instantiated on first use. pip install voicegateway[openai] installs only the OpenAI SDK.

  3. Transparent instrumentation -- InstrumentedSTT/LLM/TTS wrappers proxy all attribute access via __getattr__, so user code sees the exact same API as the underlying provider instance.

  4. Config layering -- three sources merged at startup: environment variables (highest priority), SQLite managed tables (dashboard/MCP writes), and YAML (base config). Each resource carries a source field ("yaml" or "db").

  5. Encryption at rest -- all API keys stored in SQLite are encrypted with Fernet (AES-128-CBC + HMAC-SHA256). Keys in API responses are masked to secr...2345 format.

Key Components

ComponentFilePurpose
Gateway Corecore/gateway.pyMain orchestrator, entry point for all requests
Provider Abstractionproviders/base.pyABC for all 11 provider implementations
Middlewaremiddleware/Cost, latency, rate limiting, fallback, budget
Cost Trackingpricing/, middleware/cost_tracker.pyPer-request cost calculation, pricing layer, streaming validation
Storagestorage/sqlite.pySQLite schema, tables, views, indexes
Config Layerscore/config_manager.pyYAML + SQLite + env merge strategy
Securitycore/crypto.pyFernet encryption, secret management, masking

On this page