Skip to main content
Build voice assistants with the RealtimeAgent — bidirectional audio streaming over WebSockets for live, interactive conversations.
RealtimeAgent now speaks OpenAI’s GA Realtime protocol. The default model is gpt-realtime (was gpt-4o-realtime-preview), and RealtimeConfig.temperature is deprecated — the GA API has no session temperature, so any value you pass is ignored. Your existing code keeps working; only the on-the-wire protocol moved. See Migration below.
The RealtimeAgent enables real-time voice conversations using WebSocket connections for bidirectional audio streaming. It’s designed for interactive voice applications, live transcription, and real-time AI assistants.

Quick Start

1

Simple Usage

Connect and start a conversation.
2

With Configuration

Choose a voice and tune turn detection.

How It Works

Installation

RealtimeAgent requires the websockets package for WebSocket connections.

Basic Usage

Simple Voice Assistant

With Custom Configuration

Configuration

RealtimeConfig Options

Methods

Connection Methods

Sending Data

Receiving Data

Async Usage

Voice Options

Example: Interactive Voice Bot

Error Handling

Best Practices

Keep turn_detection="server_vad" so the agent knows when the user has stopped speaking. Without server-side VAD, conversations feel stilted and responses arrive at the wrong moments.
WebSocket connections drop. Wrap connect() in reconnection logic and catch ConnectionError so a dropped link doesn’t end the session.
Collect audio chunks from on_audio before playing them. Playing raw chunks as they arrive produces choppy, garbled speech.
Long instructions slow the first response. A brief prompt keeps latency low, which matters far more in voice than in text.

Migration from beta Realtime

Existing code keeps working; check these three cases.
Switch to model="gpt-realtime", or drop the argument to use the default. The preview model is still accepted when you pass it explicitly.
Remove it. The GA API has no session temperature, so the value is ignored and emits a DeprecationWarning.
Still supported. The agent picks the right header argument (extra_headers on 12/13, additional_headers on 14+). The declared range is websockets>=12.0.

Generate and execute code with the CodeAgent.
Analyze images and visual content.