GET /v1/realtime
Handshake and protocol
Connect to placeholder URLwss://gateway.example.com/v1/realtime?model=YOUR_MODEL_ID with a WebSocket client and Bearer gateway token. The model query is required and URL-encoded. There is no JSON body. Successful upgrade returns HTTP 101; failures may be HTTP 4xx/5xx, and upgraded connections can still receive errors or close.
This site uses GA session configuration and response.output_* events. The OpenAI adapter adds upstream Beta identification only for legacy mapped model names containing -realtime-preview; that does not imply event conversion. Do not mix Beta modalities / input_audio_format / response.audio.delta with the GA fields here.
Client events and fields
Realtime client events defines the protocol; the gateway and model may not support every extension. The script disables tools and VAD and generates one turn. These are three separate messages illustrating text mode:
Server events and correlation
Correlate content by response_id, item_id, output_index, and content_index. The final response.done does not contain complete audio bytes; retain audio deltas. Audio done can also occur on unsuccessful termination, so check final status. See the server event reference for upstream structures.
Audio format and limits
The example requests PCM16LE, 24 kHz, mono throughaudio.input.format / audio.output.format using type: audio/pcm, rate: 24000; voice is audio.output.voice. turn_detection: null disables automatic VAD. The script validates effective configuration before sending input. Other formats, voices, and rates require model support and cannot simply be saved as PCM WAV.
The backend can impose connection, stream-idle, and realtime request limits. Disconnection proves neither success nor non-execution. Retain completion state and playback position, and do not automatically resend audio. Browser temporary keys, WebRTC, SIP, and Live API are not automatically covered by this route.
Source: router/relay-router.go, relay/channel/openai/adaptor.go, relay/channel/openai/relay_realtime.go, checked at 30a6d88a4. This portable Markdown page documents handshake and events without pretending they are an ordinary JSON REST operation.
Runnable text and audio example · Connection module
阅读中文