Realtime API
The realtime endpoints give applications a low latency, bidirectional session with a model, for voice assistants and live transcription. The gateway serves the OpenAI realtime protocol, a WebSocket at /v1/realtime, and HTTP endpoints for WebRTC calls, ephemeral client secrets and transcription sessions. Sessions are authenticated with a virtual key, and their usage is costed from the audio and text token counts the provider reports, so voice traffic shows up in the same budgets as text.
Scenario
A company builds a voice assistant that runs in the browser. The browser must never hold the long lived virtual key, so the application server asks the gateway for a short lived client secret and hands it to the browser, which opens a WebRTC call through the gateway. Each session is logged as one request with its audio usage, and the team's key budget caps what the assistant can spend.
Steps
-
Register a realtime model. In the Admin UI open Models + Endpoints (
/ui/models-and-endpoints), click Add Model, pick the Provider, choose the model, set the Public Model Name togpt-realtimeand set Mode to Realtime - /realtime, then click Add Model.model_list:- model_name: gpt-realtimespanway_params:model: openai/gpt-realtimeapi_key: os.environ/OPENAI_API_KEYmodel_info:mode: realtime -
Create a key in Virtual Keys (
/ui/api-keys) and pick the model under Models. -
From your server, mint a client secret for the browser.
curl -X POST http://localhost:4000/v1/realtime/client_secrets \-H "Authorization: Bearer $SPANWAY_API_KEY" \-H "Content-Type: application/json" \-d '{"session": {"type": "realtime", "model": "gpt-realtime"}, "expires_after": {"anchor": "created_at", "seconds": 600}}' -
In the browser, open the WebRTC call with the secret as the bearer token and the SDP offer as the body,
POST /v1/realtime/callswithContent-Type: application/sdp. The gateway answers with the provider's SDP answer. For a WebSocket client instead, connect tows://localhost:4000/v1/realtime?model=gpt-realtimewith the virtual key in theAuthorizationheader and exchange realtime events. -
Try a session in the browser. Open Playground (
/ui/playground), set Endpoint Type to/v1/realtime, pick the model and a Voice, click Connect and talk or type. Then open Logs (/ui/logs) to see the session with its usage.
Expected result
The client secret call answers with {"value": "ek_9e0f1a2b", "expires_at": 1760441834, "session": {...}}. The call exchange answers 200 with an SDP body, and the session appears in Logs as one request once it ends, with the aggregated audio and text usage and cost.
WebSocket sessions
Connect to ws://localhost:4000/v1/realtime?model=<model_name> with the virtual key in the Authorization header, then exchange realtime events as defined by the OpenAI protocol. The gateway relays events to the provider and back, records usage when the session ends, and applies the key's budget. Clients that send the key in the api-key header, as older realtime clients do, are accepted too. The model query parameter is required. Without it the gateway closes the WebSocket with code 1008 and the reason model query parameter is required. The one exception is intent=transcription, which uses gpt-realtime-whisper when no model is given. Two more query parameters are accepted: intent names the kind of session, such as transcription, and guardrails takes a comma-separated list of guardrail names to run on the session, for example ws://localhost:4000/v1/realtime?model=gpt-realtime&guardrails=pii-mask.
WebRTC and client secrets
| Method | Path | Summary |
|---|---|---|
| POST | /v1/realtime/calls | Start a WebRTC realtime call |
| POST | /v1/realtime/client_secrets | Create an ephemeral realtime client secret |
| POST | /v1/realtime/transcription_sessions | Create a realtime transcription session |
| GET | /v1/realtime | Open a realtime voice or transcription WebSocket session |
POST /v1/realtime/client_secrets returns a short lived secret for the browser, so the long lived virtual key stays on your server. The body must name the model, there is no default. The secret must be minted with a virtual key, because it carries that key. POST /v1/realtime/calls exchanges the browser's SDP offer for the provider's answer through the gateway and is authenticated with the client secret, not with a virtual key. Each call runs as the virtual key that minted the secret: its budget, rate limits, model list and blocked state are checked again on the call, so blocking or deleting the key also stops the secrets it minted. POST /v1/realtime/transcription_sessions starts a transcription only session.
Who changed what
Minting a client secret, through client_secrets or transcription_sessions, writes an audit row on the key with the model, the session type and the expiry, never the secret. Read it on the Logs page, Audit Logs tab, see audit logs.
Newer OpenAI session routes
OpenAI session routes the gateway has no native handler for, such as /v1/live/sessions, can be reached through the OpenAI pass-through at /openai/v1/live/sessions, over HTTP or WebSocket. The pass-through checks the virtual key and logs the call, but model routing and fallbacks do not apply there, so prefer the native realtime routes above when they cover what you need.
Gateway features
Realtime sessions are logged as one request with the aggregated usage, so they appear on the Logs page and count against budgets. Guardrails with the realtime_input_transcription mode screen the transcribed user audio. Realtime models are available from OpenAI, Azure OpenAI, Gemini, Vertex AI and xAI.
Errors
| Status | What it means | Fix |
|---|---|---|
400 The request names no realtime model. Send session.model or model. | The client_secrets body names no model. | Send session.model or model. |
400 A realtime client secret can only be created with a virtual key. | The secret was requested without a virtual key, for example with the master key. | Mint it with a virtual key. |
400 on client_secrets from the provider | expires_after is out of range. | Use a shorter expiry. |
401 {"error": "Missing or invalid Authorization header"} on /v1/realtime/calls | No Authorization: Bearer header. | Send the client secret as the bearer token. |
401 {"error": "Invalid or expired token"} on /v1/realtime/calls | The bearer token is not a client secret from this gateway, or was minted before secrets were bound to keys. | Mint a new secret. |
401 {"error": "Token has expired"} on /v1/realtime/calls | The secret's expires_at has passed. | Mint a new secret. |
401, 403 or 429 in the OpenAI error shape on /v1/realtime/calls | The key that minted the secret is blocked, expired, deleted, over budget, over its rate limit or no longer allowed the model. | Fix the key, then mint a new secret. |
401 AuthenticationError on the WebSocket | No key in Authorization or api-key, or the key is expired. The socket is closed right after the handshake. | Send a live virtual key. |
403 PermissionDeniedError | The key may not use the model, or a guardrail blocked the transcribed audio. | Add the model to the key, or read the guardrail result in Logs. |
429 RateLimitError | Budget or rate limit reached. | Raise the limit on the key. |
| The Playground shows Connection failed | The browser could not open the WebSocket, usually because the gateway sits behind a proxy that does not forward WebSockets. | Allow WebSocket upgrades on the load balancer. |
Related
- Audio transcription and text to speech for the batch audio endpoints.
- OpenAI pass-through for routes without a native handler.
- Playground page for the realtime panel.
Providers
The gateway's endpoint support matrix marks 4 provider integrations as supporting this endpoint: