voicegateway package: attach, guard, register_worker, Observer, and __version__.
Installation
pip install livekit-plugins-openai livekit-plugins-deepgram livekit-plugins-cartesia. For local runtimes, install them yourself: pip install faster-whisper (Whisper), pip install kokoro-onnx onnxruntime (Kokoro), or pip install piper-tts (Piper). VoiceGateway meters all of these instances by model_id via voice-prices, and meters local/* and ollama/* for free. attach()/guard() error messages point at the upstream wheel (for example livekit-plugins-openai), not a VoiceGateway extra.
attach
attach wires a LiveKit AgentSession or Pipecat PipelineTask into the VoiceGateway middleware pipeline. It returns a session id string ("vg-<uuid4>").
Parameters
Usage
- LiveKit
- Pipecat
Return value
attach returns the session id string ("vg-<uuid4>"). Use it to correlate external logs with VoiceGateway cost rows.
Tenant attribution
Single-tenant is the default. Settenant_id only when you need per-call attribution to a specific customer within one deployment: it is stamped directly on the rows attach writes for this session, no room or transport involved. The stamp is what the hosted cloud bills per tenant against; the OSS deployment stores it for SQL analysis.
tenant_id = NULL (the single-tenant default) and appear as “unattributed” downstream.
See Attach guide for a full walkthrough.
guard
guard wraps a native provider instance with fallback chains, rate limiting, and per-project budget enforcement. It returns a drop-in wrapper of the same framework type as provider (a subclass of the matching LiveKit/Pipecat STT, LLM, or TTS base class), so it slots into an AgentSession or pipeline unchanged. guard writes no metrics itself; pair it with attach(session) for cost and latency, which never double-counts.
Parameters
Errors
rate_limit and budget are parsed eagerly: a string that does not match the DSL (for example rate_limit="60" with no unit) raises ValueError at guard() call time, not at request time.
At call time, a guarded provider can raise:
Both subclass
voicegateway.middleware.base_middleware.MiddlewareError.
Usage
- LiveKit
- Pipecat
Return value
guard returns a wrapper of the same framework type as provider. Provider calls pass through to the underlying implementation, then to the fallback chain on error.
See Guard guide for fallback chain behavior and error handling.
register_worker
- Collector mode (
collector_urlorVOICEGW_COLLECTOR_URLset): an asyncio task pushes presence to the collector’sPOST /v1/agents/heartbeat. Needs a running event loop. - Local mode (
local=True, no collector): a background thread writes presence straight to the shared SQLite (db_path/VOICEGW_DB_PATH/ the default), which the co-located dashboard reads. Needs no event loop, so a worker registered in a plain__main__block is visible while idle immediately.
local=True, the worker is tracked in-process but nothing is pushed anywhere.
dispatch_name is the LiveKit agent_name this worker dispatches under, which the dashboard’s probe button uses to place a call by name. Left unset, it defaults to agent_name. Pass an explicit None for a worker with no LiveKit dispatch (a Pipecat agent), which keeps it in the roster but not probeable by name.
One writer per agent identity
In the LiveKit process-executor model (agent dev / agent start), the worker is the main process and per-call work runs in spawned job subprocesses. Call register_worker("agent", local=True) once in your __main__ block, and do not also pass attach(heartbeat=True) in the job: the subprocess would become a second writer of the same roster row. attach(heartbeat=True) is for single-process agents (Pipecat, or the LiveKit thread executor), where attach is the sole writer.
Observer
Observer is the Pipecat integration class. Pass it to PipelineTask(observers=[...]) to wire VoiceGateway cost tracking and metrics capture into a Pipecat pipeline.
Constructor parameters
Observer implements the Pipecat BaseObserver protocol. It captures per-frame STT, LLM, and TTS events and flushes them to the VoiceGateway collector on pipeline shutdown.