The OpenAI Realtime API lets an application hold a live spoken conversation with a model: audio goes in, the model reasons, and audio comes back within a fraction of a second, all over one open session. It is the foundation for voice assistants, phone agents, live translation, and hands-free interfaces. This guide explains how the API works today, which connection type to choose, how to handle interruptions and tools, what it costs, and what to put in place before real users depend on it.
What the Realtime API Actually Is
Traditional voice assistants chain three services together: speech-to-text turns the caller’s audio into words, a language model writes a reply, and text-to-speech reads it aloud. Each hop adds delay and strips away information such as tone and hesitation. The Realtime API collapses that chain for the conversational loop. You open a stateful session, stream audio into it, and receive audio and text events back, with the model handling listening and speaking directly. The session keeps the conversation history, so each new response is generated with the earlier turns, your instructions, and your tool definitions as context.
That convenience comes with a trade-off. You no longer have a text checkpoint between hearing and answering, which matters if you need to inspect, redact, or approve what was said before the model responds. If your use case demands that control, a chained pipeline may still be the better design. If natural pacing and low latency matter most, speech-to-speech is the stronger starting point.
The Current Model Lineup
OpenAI now documents separate models for separate jobs. A full voice-agent model and a cheaper mini variant handle conversational agents that listen, reason, speak, and call tools. A dedicated translation model streams translated speech while the original speaker is still talking, and a dedicated transcription model streams text only with no assistant reply. These are different session types, not interchangeable price tiers. A transcription session is not a discount voice agent, and a translation session does not follow the normal assistant turn cycle, so choose the session type around the output you actually need. Model names change often, so read the current model list on OpenAI’s documentation before you hard-code an identifier, and pin the version you tested.
Figure 1 — Realtime API: which connection to use
Choosing a Connection Type
The right transport depends on where the audio originates. WebRTC is OpenAI’s recommended choice for browsers and mobile apps. It handles audio as proper media tracks, copes with real-world network jitter, and carries control events such as tool calls on a separate data channel. WebSocket suits trusted servers that already hold the audio stream, such as a media pipeline you operate. It gives you fine control but makes you responsible for encoding audio chunks, buffering, and playback timing. SIP is for telephone calls: a carrier routes calls to OpenAI’s SIP endpoint, and your server accepts, configures, transfers, or hangs up each call through signed webhooks. The carrier, phone numbers, and call operations remain your responsibility whichever route you pick.
Connecting a Browser Voice Agent Safely
The key rule is that your standard API key never reaches the browser. Instead, a small endpoint on your server authenticates the user, then asks OpenAI to mint a short-lived client secret for a realtime session, specifying the model and voice. The server returns that temporary credential to the page. The browser then connects with it, either through the OpenAI Agents SDK for JavaScript, which wraps the whole WebRTC handshake, or through a lower-level implementation that creates a peer connection, adds the microphone track, and exchanges session descriptions with the calls endpoint. Rate-limit and authorise the token endpoint, because anyone who can call it can spend your money. Attach a stable, anonymised identifier for each end user so that abuse can be traced without exposing personal data.
Avoid Beta-Era Tutorials
A large share of Realtime tutorials online were written for the preview release and will mislead you. The generally available API no longer uses the beta header those examples send. Credentials come from the client secrets endpoint, WebRTC sessions are established through the calls endpoint, output audio settings sit under the session’s audio configuration, and event names have changed, for example audio deltas now arrive as output audio delta events. When you copy code from an article, check its date, check the model identifier, and compare the events it handles against the current API reference. Treat older examples as explanations of the architecture rather than code to paste.
Turn Detection and Interruptions
Two settings shape how natural a conversation feels. Turn detection decides when the user has finished speaking. Server voice activity detection ends a turn after a configurable stretch of silence, with adjustable sensitivity and padding. Semantic detection also considers whether the sentence sounds complete, and lets you choose how eagerly the model jumps in. Lower eagerness gives hesitant speakers more room, while higher eagerness answers sooner. You can disable automatic detection entirely for push-to-talk interfaces, in which case your code commits the audio and asks for a response.
Interruptions are the second challenge. When a user talks over the assistant, playback must stop, and the conversation record must also drop whatever the user never heard. On WebRTC and SIP with detection enabled, the server truncates unplayed audio automatically. Over WebSocket, your client owns playback, so it must stop the audio, work out how much was actually played, and tell the server to truncate that assistant item. Skip this step and the model will continue as if it had finished a sentence the caller only half heard.
Tools and Function Calling in Voice
Voice agents become useful when they can act: look up an order, book a slot, update a record. Define each tool with a narrow schema and a clear description. When the model emits a completed function call, your server should validate the arguments, check that the caller is authorised, run the operation with a timeout, add the result to the conversation as a function output tied to the call ID, and then request a new response so the model can explain the outcome aloud. Keep side effects on your server and make writes idempotent, because speech is messy: callers correct themselves, interrupt mid-request, and change their minds, and the same event can arrive twice. An idempotency key prevents a double booking or duplicate payment.
Prompting for Voice
Voice prompts differ from chat prompts. Tell the model to keep answers short, speak in plain sentences, and avoid reading out lists, URLs, or formatting. Ask it to confirm critical details such as names, numbers, and dates by repeating them back. Specify pacing and tone explicitly, and describe what to do when it did not hear clearly, which is to ask the caller to repeat rather than guess. Give it a clear escalation rule for when to hand the caller to a human. Test with real accents, background noise, and interruptions, because a prompt that works in a quiet office often fails on a noisy street.
Understanding the Cost
Realtime pricing is per token, split by modality, and audio is far more expensive than text. As a rule of thumb from OpenAI’s documentation, user audio works out to roughly one token per 100 milliseconds and generated audio to roughly one token per 50 milliseconds. At the full model’s audio rates published at the time of writing, that is about two cents for a minute of the user speaking and about eight cents for a minute of the assistant speaking, with the mini model costing considerably less. Check the current pricing page, because rates change. Real sessions cost more than the audio alone, since every response is generated with the accumulated conversation as input, so later turns carry more tokens. Caching of an unchanged prefix lowers that cost, so keep instructions and tool definitions stable. For long calls, cap the context or summarise older turns. Most importantly, read the token usage reported in each response event and aggregate it by session and customer, so you find out real costs in a pilot instead of in the invoice.
Measuring Latency Properly
People notice very small gaps between conversational turns, so measure what the user actually experiences: the time from the end of their speech to the first audible word of the reply. That figure includes endpoint detection, network transport, model time, any tool calls, and audio playback. Model inference time alone hides most of it. Record this at percentiles rather than averages, because the slowest turns are the ones callers remember, and track tool latency separately so a slow database does not get blamed on the model.
Production Checklist
- Durable state: store workflow state and tool results outside the session, so a dropped connection does not lose the transaction.
- Recovery: treat a reconnect as a new session, restore only the safe minimum of context, and never replay a write whose outcome is uncertain.
- Session limits: sessions have a maximum length, currently up to 60 minutes, and the output voice cannot change once audio has been produced, so design long calls accordingly.
- Testing: rehearse noise, accents, long pauses, double talk, voicemail, and abrupt interruptions, and re-run those conversations whenever you change a prompt, tool, voice, or model.
- Data handling: decide what audio and transcripts you keep, apply redaction and retention rules, and tell users when they are speaking to an AI.
- Failure paths: set rate-limit handling, timeouts, and a graceful spoken fallback when the provider or carrier has an outage.
Frequently Asked Questions
- Is the Realtime API only for WebSockets?
- No. WebSocket is one option. WebRTC is recommended for browsers and mobile apps, and SIP handles phone calls. Pick the transport based on where the audio comes from.
- Do I still need separate speech-to-text and text-to-speech services?
- Not for a speech-to-speech agent, which handles audio directly. Optional input transcription is available if you want a text record, and a chained pipeline remains sensible when you need an explicit text checkpoint or interchangeable speech providers.
- Can I use it from Python?
- Yes. A Python server can connect over WebSocket and exchange events and audio. Browser microphone experiences are usually built in JavaScript because WebRTC runs in the client.
- Can it answer phone calls?
- Yes, through SIP. Route a number through a carrier trunk to OpenAI’s SIP endpoint and accept each call from a signed webhook. You still manage the carrier, numbers, and call transfer rules.
Last updated: November 2026. Model names, endpoints, and prices change quickly, so confirm details in OpenAI’s current documentation before building.