Text-based agents are powerful, but voice unlocks an entirely different class of experience: hands-free interfaces, accessibility tools, customer service bots that feel natural to talk to, and telephony systems that don’t force users to navigate menus. The OpenAI Realtime API makes this accessible by handling the hardest parts — audio streaming, speech recognition, turn detection, and speech synthesis — so you can focus on the agent behavior itself. This guide covers the Realtime API’s core features, shows how to connect it to the Agents SDK, and walks through the patterns you’ll need for production voice agents.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/openai/openai-cookbook/llms.txt
Use this file to discover all available pages before exploring further.
What the Realtime API provides
The Realtime API is a WebSocket-based API that streams audio in both directions simultaneously. Unlike a pipeline that chains Whisper → GPT-4o → TTS, the Realtime API uses a single model that accepts and produces audio natively, which eliminates the latency introduced by converting between modalities at each step.Real-time audio streaming
Audio is streamed in chunks rather than sent as a complete file. Responses begin before the full input has been processed.
Voice activity detection
The API detects when the user stops speaking and automatically triggers a response, removing the need to manage push-to-talk logic.
Interruption handling
If the user speaks while the model is responding, the model stops mid-sentence and yields to the new input — matching natural conversation patterns.
Context management
The session maintains conversation history across turns, and the
truncation parameter automatically manages context size to preserve cache efficiency.Creating a Realtime session
A Realtime session captures your configuration: the model, the voice, the system instructions, and audio format preferences. Create one with the OpenAI Python SDK:The
sessions.create call returns a short-lived session token. Use this token to open the WebSocket connection from your client application. Do not expose your full API key to frontend code.Available voices
Six voices are available. Each has a distinct character suited to different contexts:alloy
Neutral and balanced. A good default for general-purpose assistants.
echo
Deep and measured. Works well for authoritative or informational content.
shimmer
Warm and approachable. Suited to consumer-facing and healthcare contexts.
ash
Crisp and professional. A strong choice for enterprise and productivity apps.
coral
Bright and conversational. Natural fit for customer service interactions.
sage
Calm and deliberate. Effective for educational or coaching scenarios.
Audio formats
The Realtime API supports the following audio formats for both input and output:| Format | Description |
|---|---|
pcm16 | Raw 16-bit PCM at 24 kHz, mono. Lowest latency; no decoding overhead. |
g711_ulaw | 8 kHz μ-law PCM. Standard for telephony (PSTN, SIP). |
g711_alaw | 8 kHz A-law PCM. Telephony standard common in Europe and Asia. |
pcm16 provides the best quality. For telephony integrations, use the appropriate G.711 variant to avoid transcoding.
Connecting voice to the Agents SDK
The Agents SDK’s voice extension lets you run any agent graph through a voice pipeline with minimal changes. Install the voice extra:VoicePipeline:
Building a multi-agent voice assistant
The voice pipeline composes with the orchestrator pattern. You can build a triage agent that routes voice requests to specialist agents — and the user experiences it as a single coherent conversation:Setting up the voice pipeline end to end
Define your agent graph
Create your agents, attach tools, and configure handoffs as you would for a text-based workflow. The voice layer wraps any existing agent graph.
Create the pipeline
Wrap your entry-point agent in a
VoicePipeline using SingleAgentVoiceWorkflow or a custom workflow class for more control over the session lifecycle.Connect audio I/O
Pass an audio input source (microphone stream) and audio output sink (speakers or buffer) to the pipeline. The SDK handles VAD, chunking, and playback timing.
Context and long conversations
Voice conversations can run long. The Realtime API supports a 32k token context window, but quality can degrade as the context fills up. Two strategies help:- Automatic truncation
- Manual summarization
Set the
truncation parameter in your session configuration. The API automatically compresses older context to stay within the window while preserving recent turns and cache efficiency:Use cases
Customer service bots
Route inbound calls to billing, technical support, or account management specialists. Handoffs happen mid-conversation without the user being transferred to a different system.
Voice interfaces for apps
Add a voice entry point to any existing in-app workflow. Users speak naturally; the triage agent routes to the right specialist in the background.
Telephony integration
Use G.711 audio formats to connect voice agents to PSTN or SIP infrastructure. The model handles the conversation; your telephony layer handles routing and recording.
Accessibility tools
Serve users who find text interfaces difficult by providing a natural voice alternative to any capability your agent graph already supports.
Further reading
- Voice agents quickstart — getting audio in and out of the Agents SDK
- App assistant voice agents notebook — the full multi-agent voice demo this guide is based on
- Context summarization with the Realtime API — managing long voice sessions
- Realtime API reference — complete parameter documentation
- Orchestrating agents — handoff patterns used by the triage agent in voice workflows