Skip to content

LiveKit: realtime LLM

Hold a live voice conversation through LiveKit Agents' realtime model.

Overview

openai.realtime.RealtimeModel replaces separate STT, LLM, and TTS stages with a single WebSocket to a model that listens and speaks.

Basic usage

Pass it as an Agent's llm:

import os

from livekit.agents import Agent, AgentSession
from livekit.plugins.openai.realtime import RealtimeModel

agent = Agent(
    instructions="Be concise and stay on topic.",
    llm=RealtimeModel(
        model="symphony",
        base_url="wss://api.sprag.ai/v1/realtime",
        api_key=os.environ["SPRAG_API_KEY"],
    ),
)

session = AgentSession()
# session.start(room=ctx.room, agent=agent)

Configuration

Constructor arguments

ArgumentTypeDefaultDescription
modelstr--A Sprag speech-to-speech model id. Required.
base_urlstr--wss://api.sprag.ai/v1/realtime
api_keystrOPENAI_API_KEY env varYour Sprag API key
turn_detectiondictserver VADEndpointing on the realtime session

Instructions

Agent's instructions maps onto the session's instructions field: persona, behavior, task guidance. See session configuration.

Turn timing

Turn detection follows the same turn_detection settings the raw protocol takes. Configure it the same way as the STT service.

Reference