翻篇收录说明
翻篇网页快照

OpenAI Realtime API | LiveKit Documentation

https://docs.livekit.io/agents/models/realtime/openai/

最近抓取:2026-12-03 18:50:53(北京时间)

最近内容变化:2026-12-03 18:50:53(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

How to use the OpenAI Realtime API with LiveKit Agents.

正文摘录

OverviewThe OpenAI Realtime API enables low-latency, multimodal interactions with realtime text, audio, image, and video features. OpenAI realtime models are available in LiveKit Agents through LiveKit Inference and the OpenAI plugin. With LiveKit Inference, you use your LiveKit Cloud credentials instead of a separate OpenAI API key, and LiveKit Cloud bills you for usage. Use the plugin instead if you want to manage your own billing.LiveKit Inference Use LiveKit Inference to access OpenAI realtime models without a separate OpenAI API key.OpenAI hosted on AzureLiveKit Inference serves OpenAI realtime models from both OpenAI and Azure, and automatically uses the best available provider. To use a specific provider, set provider to openai or azure.The following table lists the OpenAI realtime models available through LiveKit Inference.A checkmark in the EU endpoint column means the model has a dedicated EU endpoint, in addition to the global endpoint. To learn more, see Data residency.Model nameModel IDEU endpointGPT-Live 1.1openai/gpt-live-1.1No EU endpointGPT Realtime 2.1openai/gpt-realtime-2.1EU endpointGPT Realtime 2.1 miniopenai/gpt-realtime-2.1-miniEU endpointUsage Use the RealtimeModel class from the inference module to run OpenAI realtime models through LiveKit Inference. You can use this model in the Voice AI quickstart:PythonNode.jsfrom livekit.agents import AgentSession, inference session = AgentSession( llm=inference.RealtimeModel(model="openai/gpt-realtime-2.1", voice="marin"),)import { AgentSession, inference } from '@livekit/agents'; const session = new AgentSession({ llm: new inference.RealtimeModel({ model: 'openai/gpt-realtime-2.1', voice: 'marin' }),});Authentication uses your LiveKit Cloud credentials. Set LIVEKIT_API_KEY and LIVEKIT_API_SECRET in your .env file, or pass api_key and api_secret directly. In Node.js, these parameters are apiKey and apiSecret.Parameters The following are the main parameters for configuring OpenAI realtime models with LiveKit Inference. For a complete list, see the API reference for Python and Node.js.modelRequiredstringThe model to use. Must be an OpenAI model ID from the models list, including the openai/ prefix.providerstringDeprecated. Support for provider pinning ends on March 1, 2027. Omit provider to let LiveKit route requests and use fallback providers. See provider pinning deprecation for migration guidance.voicestringDefault: 'marin'Voice to use for speech generation. For a list of available voices, see Voice options .turn_detectionTurnDetection | NoneConfiguration for turn detection. For more information, see Turn detection.In Node.js, use turnDetection.modalitieslist[str]List of response modalities to use for the session. Set to ['text'] to use the model in text-only mode with a separate TTS.input_audio_transcriptionAudioTranscription | NoneConfiguration for transcribing user audio.In Node.js, use inputAudioTranscription.tool_choiceToolChoice | NoneControls how the model uses tools, such as auto, none, or required.In Node.js, use toolChoice.reasoningRealtimeReasoning | NoneReasoning configuration for reasoning-capable models, with no effect on models without reasoning support. Set the effort field to control how much the model reasons before responding.speedfloatDefault: 1.0Speed of the model's spoken response, as a multiple of the original speed. Valid values are between 0.25 and 1.5. The speed changes only between model turns, not during a response.input_audio_noise_reductionNoiseReductionType | NoiseReduction | NoneNoise reduction for user audio before it reaches turn detection and the model. Set to near_field for close-talking microphones, such as headsets, or far_field for far-field microphones, such as laptop or conference room microphones.In Node.js, use inputAudioNoiseReduction.api_keystringLiveKit API key. Defaults to the LIVEKIT_API_KEY environment variable.In Node.js, use apiKey.api_secretstringLiveKit API secret. Defaults to the LIVEKIT_API_SECRET environment variable.In Node.js, use apiSecret.Usage with separate TTS To use an OpenAI realtime model through LiveKit Inference with a different TTS instance, set a text-only response modality and add a TTS instance to your AgentSession. This setup is a realtime hybrid architecture.PythonNode.jsfrom livekit.agents import AgentSession, inference session = AgentSession( llm=inference.RealtimeModel(model="openai/gpt-realtime-2.1", modalities=["text"]), tts="fishaudio/s3-pro:fa4c9eb3dccc4806b382b40d61c6b10a", # Or other TTS instance of your choice)import { AgentSession, inference } from '@livekit/agents'; const session = new AgentSession({ llm: new inference.RealtimeModel({ model: 'openai/gpt-realtime-2.1', modalities: ['text'] }), tts: 'fishaudio/s3-pro:fa4c9eb3dccc4806b382b40d61c6b10a', // Or other TTS instance of your choice});Azure LiveKit Inference serves openai/gpt-realtime models from both OpenAI and Azure and selects between them for you. You don't configure Azure yourself. The with_azure() method and its azure_deployment, entra_token, and api_version arguments from the Azure plugin don't apply. In Node.js, the equivalents are withAzure(), azureDeployment, entraToken, and apiVersion.Provider pinning is deprecated, with support ending on March 1, 2027. Omit provider to keep automatic routing and fallback. If you require your own Azure deployment, use the Azure OpenAI plugin.String descriptorsAs a shortcut, you can also pass the model ID directly to the llm argument in your AgentSession:PythonNode.jsfrom livekit.agents import AgentSession session = AgentSession( llm="openai/gpt-realtime-2.1",)import { AgentSession } from '@livekit/agents'; const session = new AgentSession({ llm: 'openai/gpt-realtime-2.1',});PluginUse the OpenAI plugin to connect directly to the OpenAI Realtime API with your own API key. Available inPython|Node.jsInstallationInstall the OpenAI plugin:PythonNode.jsuv add "livekit-agents[openai]~=1.8"pnpm add "@livekit/agents-plugin-openai@1.x"AuthenticationThe OpenAI plugin requires an OpenAI API key .Set OPENAI_API_KEY in your .env file.Usage Use the OpenAI Realtime API within an AgentSession. For example, you can use it in the Voice AI quickstart.PythonNode.jsfrom livekit.plugins import openai session = AgentSession( llm=openai.realtime.RealtimeModel(voice="marin"),)import * as openai from '@livekit/agents-plugin-openai'; const session = new voice.AgentSession({ llm: new openai.realtime.RealtimeModel({ voice: "marin" }),});Parameters This section describes some of the available parameters. For a complete reference of all available parameters, see the plugin reference links in the Additional resources section.modelstrDefault: 'gpt-realtime'ID of the Realtime model to use. For a list of available models, see the Models .voicestrDefault: 'marin'Voice to use for speech generation. For a list of available voices, see Voice options .temperaturefloatDefault: 0.8Sampling temperature that controls the randomness of the model's output. Higher values make the output more random, while lower values make it more focused and deterministic. Range of valid values can vary by model.Valid values are between 0.6 and 1.2. To learn more, see temperature .turn_detectionTurnDetection | NoneConfiguration for turn detection, see the section on Turn detection for more information.modalitieslist[str]Default: ['text', 'audio']List of response modalities to use for the session. Set to ['text'] to use the model in text-only mode with a separate TTS plugin.reasoningRealtimeReasoning | NoneDefault: NoneReasoning configuration for reasoning-capable models, with no effect on models without reasoning support. Set the effort field to control how much the model reasons before responding. In Python you can also pass reasoning to update_options() to change it mid-session.speedfloatDefault: 1.0Speed of the model's spoken response, as a multiple of the original speed. Valid values are between 0.25 and 1.5. The speed changes only between model turns, not during a response.input_audio_noise_reductionNoiseReductionType | NoiseReduction | NoneNoise reduction for user audio before it reaches turn detection and the model. Set to near_field for close-talking microphones, such as headsets, or far_field for far-field microphones, such as laptop or conference room microphones.In Node.js, use inputAudioNoiseReduction.Video input ONLY Available inPythonThe OpenAI Realtime API supports live video input. When enabled, the agent receives frames from the user's camera or screen share and sends each frame to the model as an image message.Video input requires the OpenAI plugin. LiveKit Inference doesn't support image or video input for realtime models.To enable video, set video_input=True in your RoomOptions: agent.py Required importsclass VideoAssistant(Agent): def __init__(self) -> None: super().__init__( instructions="You are a helpful voice assistant with live video input from your user.", llm=openai.realtime.RealtimeModel(voice="marin"), ) server = AgentServer() @server.rtc_session(agent_name="my-agent")async def my_agent(ctx: JobContext): session = AgentSession() await session.start( agent=VideoAssistant(), room=ctx.room, room_options=room_io.RoomOptions( video_input=True, ), )from livekit.agents import ( Agent, AgentServer, AgentSession, JobContext, room_io,)from livekit.plugins import openaiBy default, the agent samples one frame per second while the user speaks and one frame every three seconds otherwise. To control the frame rate, pass a video_sampler to the AgentSession.For more details on video input configuration, see Live video input.Usage with separate TTS To use the OpenAI Realtime API with a different TTS instance, configure it with a text-only response modality and include a TTS instance in your AgentSession configuration. This configuration allows you to gain the benefits of realtime speech comprehension while maintaining complete control over the speech output.PythonNode.jssession = AgentSession( llm=openai.realtime