Skip to main content
One runnable LiveKit agent file. Copy it, set your keys, run it.

Prerequisites

  • Python 3.11 or later
  • VoiceGateway installed for LiveKit (see Installation)
  • A LiveKit server: a LiveKit Cloud project, or livekit-server --dev locally
  • API keys for Deepgram, OpenAI, and Cartesia (swap in your own providers)

Install

VoiceGateway is framework-agnostic and does not bundle provider wheels. You install the LiveKit plugins your agent uses, and VoiceGateway meters them by model_id through voice-prices.

Set environment variables

For local development with livekit-server --dev, use:
The worker exits at startup without LIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET set.

agent.py

Run the agent

Connect from a browser or the LiveKit Playground, say something, and watch the dashboard.

What happens

  1. deepgram.STT transcribes speech. attach() meters audio minutes and cost.
  2. 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.
  3. cartesia.TTS synthesizes speech. attach() meters characters and cost.
  4. 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, without guard(), is a complete and valid setup: you get cost and latency tracking with no change to how the call behaves. Reach for guard() only on the providers where you want fallback, a rate limit, or a spend cap.
  • guard() returns the same type it wraps, so guarded_llm slots into AgentSession exactly like a plain openai.LLM.

Next steps