colossal-lock-10836
09/02/2025, 3:23 AMtall-airline-16756
09/02/2025, 3:23 AMtall-airline-16756
09/02/2025, 3:23 AMpip install "livekit-agents[openai]~=1.2"
2. Authentication: Next, pop your OpenAI API key into the .env file like this:
OPENAI_API_KEY=your_api_key_here
3. Usage: Now, create a RealtimeModel instance and pass it to an AgentSession. Here’s a quick example:
from livekit.agents import AgentSession
from livekit.plugins import openai
session = AgentSession(
llm=openai.realtime.RealtimeModel()
)
If you’re working with Node.js, you can do it like this:
import { RealtimeModel } from '@livekit/agents-plugin-openai';
const session = new AgentSession({
llm: new RealtimeModel(),
});
4. Configuration: Feel free to tweak parameters like model, voice, temperature, and turn detection to fit your needs. Here’s an example:
session = AgentSession(
llm=openai.realtime.RealtimeModel(
model="gpt-4o-realtime-preview",
voice="shimmer",
temperature=0.7
)
)
And if you’re using Azure OpenAI, just use the with_azure method and set up your Azure-specific environment variables.
Want to dive deeper? Check out the OpenAI Realtime API integration guide for all the details. Happy coding!
Sources: Azure AI Services and LiveKit | LiveKit Docs | OpenAI and LiveKit partner to turn Advanced Voice into an API | OpenAI Realtime API integration guide | LiveKit Docs | Realtime model integrations | LiveKit Docs | examples/src/realtime_turn_detector.ts