Skip to main content
The public Python surface is five names exported from the top-level voicegateway package: attach, guard, register_worker, Observer, and __version__.
Cost queries, project management, latency stats, and request logs live outside the Python SDK. Use the CLI, the HTTP API, the Dashboard API, or the MCP tools for those.

Installation

VoiceGateway is framework-agnostic and no longer bundles provider or local-model wheels. Install the provider plugins your agent uses in your own agent (you likely already have them), for example 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

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. Set tenant_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.
Sessions with no tenant set are stored as 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

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

Registers this process as an agent worker and starts heartbeating its presence, so it shows in the dashboard’s Fleet/Agents view (idle or busy) even before it has handled a call. Returns the agent id. Call once at worker boot. Two transports, chosen by whether a collector is configured:
  • Collector mode (collector_url or VOICEGW_COLLECTOR_URL set): an asyncio task pushes presence to the collector’s POST /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.
Without a collector and without 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.
For LiveKit agents, use attach instead of Observer. Observer is the Pipecat-specific integration path.

__version__

The installed package version string. Useful for logging and support diagnostics.

Where to go next