Prerequisites
- Python 3.11 or later
- VoiceGateway installed for LiveKit (see Installation)
- A LiveKit server: a LiveKit Cloud project, or
livekit-server --devlocally - API keys for Deepgram, OpenAI, and Cartesia (swap in your own providers)
Install
model_id through voice-prices.
Set environment variables
livekit-server --dev, use:
LIVEKIT_URL, LIVEKIT_API_KEY, and
LIVEKIT_API_SECRET set.
agent.py
Run the agent
What happens
deepgram.STTtranscribes speech.attach()meters audio minutes and cost.guard(openai.LLM(...))sends the transcript to GPT-4o mini. On an error,guard()retries with GPT-4o automatically.attach()meters prompt tokens, completion tokens, and cost.cartesia.TTSsynthesizes speech.attach()meters characters and cost.- Every row lands in the dashboard at
http://localhost:8080.
View costs
The daemon must be running first:voicegw init once, then voicegw serve in another terminal (see Quickstart).
Notes
attach()alone, withoutguard(), is a complete and valid setup: you get cost and latency tracking with no change to how the call behaves. Reach forguard()only on the providers where you want fallback, a rate limit, or a spend cap.guard()returns the same type it wraps, soguarded_llmslots intoAgentSessionexactly like a plainopenai.LLM.
Next steps
- attach(): full signature, including
tenant_idfor multi-tenant attribution. - guard(): full signature, including per-framework fallback scope.
- Frameworks and extras: the framework-neutral core.
- Configuration reference: every YAML key.
- Providers: all supported providers and model IDs.