Skip to main content
Azure OpenAI GPT Realtime API for speech and audio is part of the GPT-4o model family that supports low-latency, β€œspeech in, speech out” conversational interactions. You can use the Realtime API via WebRTC, SIP, or WebSocket to send audio input to the model and receive audio responses in real time. Follow the instructions in this article to get started with the Realtime API via WebRTC. In most cases, use the WebRTC API for real-time audio streaming. The WebRTC API is a web standard that enables real-time communication (RTC) between browsers and mobile applications. Here are some reasons why WebRTC is preferred for real-time audio streaming:
  • Lower latency: WebRTC is designed to minimize delay, making it more suitable for audio and video communication where low latency is critical for maintaining quality and synchronization.
  • Media handling: WebRTC has built-in support for audio and video codecs, providing optimized handling of media streams.
  • Error correction: WebRTC includes mechanisms for handling packet loss and jitter, which are essential for maintaining the quality of audio streams over unpredictable networks.
  • Peer-to-peer communication: WebRTC allows direct communication between clients, reducing the need for a central server to relay audio data, which can further reduce latency.
Use the Realtime API via WebSockets if you need to:
  • Stream audio data from a server to a client.
  • Send and receive data in real time between a client and server.
WebSockets aren’t recommended for real-time audio streaming because they have higher latency than WebRTC.

Supported models

You can access the GPT real-time models for global deployments in the East US 2 and Sweden Central regions.
  • gpt-4o-mini-realtime-preview (2024-12-17)
  • gpt-4o-realtime-preview (2024-12-17)
  • gpt-realtime (version 2025-08-28)
  • gpt-realtime-mini (version 2025-10-06)
  • gpt-realtime-mini (version 2025-12-15)
  • gpt-realtime-1.5 (version 2026-02-23)
  • gpt-realtime-2 (version 2026-05-07)
  • gpt-realtime-translate (version 2026-05-06)
  • gpt-realtime-whisper (version 2026-05-06)
Use the /openai/v1 path in the request URL when calling the Realtime API. For more information about supported models, see the models and versions documentation.
Use the GA protocol for WebRTC.The GA endpoints described in this article use different URLs than the Preview API:
  • GA uses /openai/v1/realtime/client_secrets and /openai/v1/realtime/calls
  • Preview (deprecated) used /openai/realtimeapi/sessions and regional URLs
If you’re a current customer using Preview endpoints, migrate to the GA Protocol.We preserve the legacy protocol documentation here.

Prerequisites

Before you can use GPT real-time audio, you need:
  • An Azure subscription - Create one for free.
  • A Microsoft Foundry resource - Create a Microsoft Foundry resource in one of the supported regions.
  • A deployment of a GPT realtime model in a supported region as described in the supported models section in this article.
    • In the Foundry portal, load your project. Select Build in the upper-right menu, then select the Models tab on the left pane, and select Deploy a base model. Search for the model you want, and select Deploy on the model page.

Set up WebRTC

To use WebRTC, you need two pieces of code:
  1. A web browser application.
  2. A service where your web browser can retrieve an ephemeral token.
Other options:
  • Proxy the web browser’s session negotiation via Session Description Protocol through the same service retrieving the ephemeral token. This scenario is more secure because the web browser doesn’t have access to the ephemeral token.
  • Filter the messages going to the web browser by using a query parameter.
  • Create an observer WebSocket connection to listen to or record the session.

Steps

Step 1: Set up service to procure ephemeral token

The key to generating an ephemeral token is the REST API using
This is the GA endpoint for WebRTC. If you’re migrating from the Preview API, the endpoint has changed:
  • Preview (deprecated): /openai/realtimeapi/sessions?api-version=2025-04-01-preview
  • GA (current): /openai/v1/realtime/client_secrets (no API version parameter needed)
For migration details, see Migration from Preview to GA version of Realtime API.
You use this URL with either an api-key or Microsoft Entra ID token. This request retrieves an ephemeral token and sets up the session configuration you want the web browser to use, including the prompt instructions and output voice. Here’s some sample Python code for a token service. The web browser application can call this service by using the /token endpoint to retrieve an ephemeral token. This sample code uses the DefaultAzureCredential to authenticate to the RealtimeAPI generating ephemeral tokens.
Replace placeholder values in the code samples:
  • <your azure resource> or <YOUR AZURE RESOURCE> - Your Azure OpenAI resource name
  • <your model deployment name> or <YOUR MODEL DEPLOYMENT NAME> - Your realtime model deployment name
The session configuration includes:

Step 2: Set up your browser application

Your browser application calls your token service to get the token and then initiates a WebRTC connection with the RealtimeAPI. To initiate the WebRTC connection, use the following URL with the ephemeral token for authentication.
This is the GA endpoint for WebRTC connections. If you’re migrating from the Preview API:
  • Preview (deprecated): https://<region>.realtimeapi-preview.ai.azure.com/v1/realtimertc
  • GA (current): https://<your azure resource>.openai.azure.com/openai/v1/realtime/calls
Once connected, the browser application sends text over the data channel and audio over the media channel. Here’s a sample HTML document to get you started.
In the sample, we use the query parameter webrtcfilter=on. This query parameter limits the data channel messages sent to the browser to keep your prompt instructions private. When the filter is turned on, only the following messages are returned to the browser on the data channel:
  • input_audio_buffer.speech_started
  • input_audio_buffer.speech_stopped
  • output_audio_buffer.started
  • output_audio_buffer.stopped
  • conversation.item.input_audio_transcription.completed
  • conversation.item.added
  • conversation.item.created
  • response.output_text.delta
  • response.output_text.done
  • response.output_audio_transcript.delta
  • response.output_audio_transcript.done
For the complete list of Realtime API events, see the API reference.
When the connection succeeds, you should see these console messages:
  • βœ… RTCPeerConnection created
  • βœ… Microphone access granted
  • βœ… Data channel is open
  • 🎡 Audio playback started
If the AI responds, you’ll see response.output_audio_transcript.done events with the transcribed response. Reference: RTCPeerConnection, Realtime API events

Step 3 (optional): Create a websocket observer/controller

If you proxy the session negotiation through your service application, you can parse the Location header that’s returned and use it to create a websocket connection to the WebRTC call. This connection can record the WebRTC call and even control it by issuing session.update events and other commands directly. Here’s an updated version of the token_service shown earlier, now with a /connect endpoint that you can use to both get the ephemeral token and negotiate the session initiation. It also includes a websocket connection that listens to the WebRTC session.
The associated browser changes are shown here.
Reference: DefaultAzureCredential, Flask documentation

Step 4 (optional): Configure Network Firewall

If you use a Network Firewall, the Realtime API requires the following Allow rule on the client side.

Troubleshooting

Authentication errors

  • 401 Unauthorized: Verify your API key or Microsoft Entra ID token is valid. Ensure the identity has the Cognitive Services User role assigned on the Azure OpenAI resource.
  • 403 Forbidden: Check that your resource is deployed in a supported region (East US 2 or Sweden Central).

Connection errors

  • WebRTC connection failed:
    • Ensure your browser supports WebRTC and allows microphone access. Check that you’re using HTTPS (required for getUserMedia).
    • If you use Network Firewall, check Firewall Settings.
  • Data channel not opening: Check the browser console for ICE connection state errors. Verify the ephemeral token hasn’t expired.
  • SDP exchange failed: Verify the WebRTC endpoint URL is correct and the ephemeral token is valid.

Model errors

  • Model not found: Verify your deployment name matches exactly (case-sensitive). Ensure you’ve deployed a realtime model (gpt-4o-realtime-preview, gpt-realtime, etc.).
  • Quota exceeded: Check your Azure OpenAI quota in the Azure portal. Realtime API has separate quota from chat completions.

Audio issues

  • No audio output: Check that audioElement.autoplay = true is set and browser autoplay policies aren’t blocking playback. Try clicking the page first to enable audio.
  • Poor audio quality: WebRTC automatically adjusts for network conditions. Check your network connection and try reducing other network traffic.