How can I use gpt-realtime model in Livekit Agents...
# ask-ai
s
How can I use gpt-realtime model in Livekit Agents SDK for python?
t
Thanks for reaching out, Mark. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to use the GPT-Realtime model in the LiveKit Agents SDK for Python, here’s a friendly step-by-step guide to get you started: 1. Install the SDK: Just run
pip install "livekit-agents[openai]~=1.2"
and make sure your OpenAI API key is set up in the
OPENAI_API_KEY
environment variable. 2. Basic Configuration: Kick things off by initializing the session with the
openai.realtime.RealtimeModel()
class. Here’s a quick example:
Copy code
from livekit.agents import AgentSession
from livekit.plugins import openai

session = AgentSession(
    llm=openai.realtime.RealtimeModel()
)
3. Customization: You can tweak settings like the model (the default is
gpt-4o-realtime-preview
), pick a voice (think
alloy
or
nova
), adjust the temperature, and choose modalities such as
["text", "audio"]
. 4. Advanced Options: There are cool features you can turn on like detecting turns, transcribing input audio, and customizing how long your session lasts. 5. Integration: If you want to use scripted speech, just pair the realtime model with a separate TTS plugin by setting
modalities=["text"]
. If you’d like, I can share a complete example or help you with any part of this—just let me know! Sources: OpenAI Realtime API integration guide | LiveKit Docs | Realtime model integrations | LiveKit Docs | examples/voice_agents/realtime_load_chat_history.py | OpenAI and LiveKit partner to turn Advanced Voice into an API