Skip to main content

Overview

The Realtime API enables low-latency, multi-modal conversational experiences using WebSocket connections. It supports text and audio as both input and output, as well as function calling. Key benefits:
  • Native speech-to-speech: Low latency by skipping intermediate text format
  • Natural voices: Models can laugh, whisper, and follow tone directions
  • Simultaneous multimodal output: Get both text and audio in real-time

Connection Setup

The Realtime API is a stateful, event-based API that communicates over WebSocket.

WebSocket Connection

Connection Parameters

string
The Realtime model to use. Required for Azure, optional for OpenAI.Examples: gpt-4o-realtime-preview, gpt-4o-realtime-preview-2024-10-01
string
Optional call identifier for tracking purposes
dict
Additional query parameters for the WebSocket connection
dict
Additional headers for the WebSocket connection
dict
WebSocket-specific connection options

Session Management

Update Session Configuration

Update session settings at any time during the connection.

Session Configuration Options

string
System instructions for the model (e.g., “Be succinct”, “Speak quickly”)
string
Voice for audio output. Options: alloy, echo, shimmerCan only be updated before any audio output has been generated.
string
Format for input audio: pcm16 or g711_ulaw or g711_alaw
string
Format for output audio: pcm16 or g711_ulaw or g711_alaw
object
Voice Activity Detection (VAD) configuration:
  • type: "server_vad" or null to disable
  • threshold: Detection sensitivity (0-1)
  • prefix_padding_ms: Audio before speech starts
  • silence_duration_ms: Silence duration to end turn
array
Function tools available to the model
string | object
How model chooses tools: auto, none, required, or force a specific function
float
Sampling temperature (0-2). Higher = more random.
int | 'inf'
Maximum tokens per response (1-4096 or "inf")

Receiving Events

Iterate Through Events

Receive Single Event

Complete Example

Async Usage

Notes

  • Installation: Requires openai[realtime] package: pip install openai[realtime]
  • Context manager: Connection is automatically closed when exiting the with block
  • Manual connection: Use .enter() method if you need to manage connection lifecycle manually
  • Azure: Model parameter is required for Azure Realtime API
  • Session configuration can be updated anytime except voice and model