Skip to main content

Using LiveKit Agents

LiveKit Agents is an open-source framework for building voice AI agents. The OpenRouter plugin allows you to access 400+ AI models from multiple providers through a unified API, with automatic fallback support and intelligent routing.

Installation

Install the OpenAI plugin to add OpenRouter support:

Authentication

The OpenRouter plugin requires an OpenRouter API key. Set OPENROUTER_API_KEY in your .env file.

Basic Usage

Create an OpenRouter LLM using the with_openrouter method:

Text-to-Speech and Speech-to-Text

The same OpenAI plugin can send your agent’s speech synthesis and transcription through OpenRouter. Point openai.TTS and openai.STT at https://openrouter.ai/api/v1 and pass an OpenRouter model ID. TTS calls the Text-to-Speech API and STT calls the Speech-to-Text API, so any model and voice those guides list works here.
The example reads OPENROUTER_API_KEY from the process environment: export it, or call load_dotenv() from python-dotenv before you build the session so the key in your .env file is loaded. This needs livekit-agents[openai] 1.9 or later (uv add "livekit-agents[openai]>=1.9"): earlier plugin versions parse the raw audio OpenRouter returns as server-sent events and play nothing. Set use_realtime=False on openai.STT so the plugin sends each utterance to the transcription endpoint instead of opening an OpenAI Realtime WebSocket; that mode needs a voice activity detector, so pass vad= to AgentSession (for example silero.VAD.load() from livekit-plugins-silero). Each model takes its own voices and output formats; read them from the speech models API before you change model.

Advanced Features

Fallback Models

Configure multiple fallback models to use if the primary model is unavailable:
Output

Provider Routing

Control which providers are used for model inference:
Output

Web Search Plugin

Enable OpenRouter’s web search capabilities:
Output

Analytics Integration

Include site and app information for OpenRouter analytics:
Output

Resources