OpenAI integration guide

An introduction to using the LiveKit Agents framework with OpenAI.

Overview

LiveKit's OpenAI integration provides support for LLM, STT, TTS, and the OpenAI Realtime API. The Quick reference section in this topic describes using OpenAI for LLM, STT, and TTS. For a guide on using the Realtime API, see the OpenAI Realtime API integration guide.

Use OpenAI STT, TTS, and LLM to create agents using the VoicePipelineAgent class. To use the Realtime API, you can create an agent using the MultimodalAgent class.

Note

The following quickstart guides are available to get you started creating an AI voice assistant with OpenAI:

Quick reference

The following sections provide a quick reference for integrating OpenAI with LiveKit. For the complete reference, see the links provided in each section.

LLM

LiveKit's OpenAI plugin provides support for creating an instance of an LLM class to be used in a VoicePipelineAgent.

LLM class usage

Create an instance of OpenAI LLM:

from livekit.plugins.openai import llm
openai_llm = llm.LLM(
model="gpt-4o",
temperature=0.8,
)

LLM parameters

This section describes some of the available parameters. For a complete reference of all available parameters, see the plugin reference.

modelstring | ChatModelsOptionalDefault: gpt-4o

ID of the model to use for inference. For a list of supported models, see ChatModels in the respective GitHub repository: Python, Node.js. To learn more about available models, see Models.

api_keystringOptionalEnv: OPENAI_API_KEY

OpenAI API key. Required if the environment variable is not set.

temperaturefloatOptionalDefault: 1.0

A measure of randomness of completions. A lower temperature is more deterministic. To learn more, see chat completions.

STT

LiveKit's OpenAI plugin allows you to create an instance of OpenAI STT that can be used as the first stage in a VoicePipelineAgent or as a standalone transcription service.

STT usage

Create an OpenAI STT:

from livekit.plugins.openai import stt
openai_stt = stt.STT(
language="en",
model="whisper-1",
)

STT parameters

This section describes some of the available parameters. For a complete reference of all available parameters, see the plugin reference.

modelWhisperModels | stringOptionalDefault: whisper-1

ID of the model to use for speech recognition. To learn more, see Whisper.

languagestringOptionalDefault: en

Language of input audio in ISO-639-1 format. See OpenAI's documentation for a list of supported languages.

TTS

LiveKit's OpenAI plugin allows you to create an instance of OpenAI TTS that can be used in a VoicePipelineAgent or as a standalone speech generator.

TTS usage

Create an OpenAI TTS:

from livekit.plugins.openai import tts
openai_tts = tts.TTS(
model="tts-1",
voice="nova",
)

TTS parameters

This section describes some of the available parameters. For a complete reference of all available parameters, see the plugin reference.

modelTTSModels | stringOptionalDefault: tts-1

ID of the model to use for speech generation. To learn more, see TTS models.

voiceTTSVoice | stringOptionalDefault: alloy

ID of the voice used for speech generation. To learn more, see TTS voice options.