OpenAIAdapter
Defined in: packages/realtime-openai/src/openai-adapter.ts:182
A RealtimeProviderAdapter that connects the browser directly to
OpenAI gpt-realtime over WebRTC: mints an ephemeral client secret via the
injected mintToken, exchanges SDP with POST /v1/realtime/calls, and
drives tool calls / grounding pushes over the oai-events data channel.
The data-channel envelope → adapter-event mapping lives in parseOpenAIServerEvent; this class owns the provider-specific WebRTC, response lifecycle, and transcript-confirmed interruption bookkeeping around that mapping. The browser’s WebRTC implementation itself is not unit-tested.
Example
Section titled “Example”const adapter = new OpenAIAdapter({ mintToken: () => fetch('/api/realtime/mint', { method: 'POST', ... }).then(r => r.json()),});const session = new RealtimeSession({ adapter, instance, sessionId });await session.connect();Implements
Section titled “Implements”RealtimeProviderAdapterRealtimeGreetingAdapter
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new OpenAIAdapter(
options):OpenAIAdapter
Defined in: packages/realtime-openai/src/openai-adapter.ts:228
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”OpenAIAdapter
Properties
Section titled “Properties”observations
Section titled “observations”
readonlyobservations:TranscriptObservationFeed
Defined in: packages/realtime-openai/src/openai-adapter.ts:205
Transcript fragments on a local receipt-time timeline, one per provider conversation item. The item’s final event revises its fragment with the full text. The fixed greeting appears as one final assistant fragment when its playback starts. Media evidence is not reported.
Implementation of
Section titled “Implementation of”RealtimeProviderAdapter.observations
Methods
Section titled “Methods”activateAudio()
Section titled “activateAudio()”activateAudio():
void
Defined in: packages/realtime-openai/src/openai-adapter.ts:539
Unlocks retained Web Audio activation in the initiating gesture.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”RealtimeGreetingAdapter.activateAudio
connect()
Section titled “connect()”connect(
opts):Promise<void>
Defined in: packages/realtime-openai/src/openai-adapter.ts:302
Mints a token, captures the microphone, and opens the browser-to-OpenAI
WebRTC session. Capture requests AEC, noise suppression, and automatic gain
control as best-effort browser preferences; it does not promise that a
browser, device, or audio route applies them. After acquisition is confirmed
as current, enabled debug logging projects only applied booleans (or
unavailable) from the original track before attachment. Superseded
acquisitions are stopped without attachment or diagnostics, and missing or
throwing settings APIs do not fail connection.
Duplicate connections are rejected. Token, microphone, and SDP failures reject after this attempt’s resources are released. Unlike LiveKit, OpenAI owns turn detection and has no local VAD clone or publication gate.
Parameters
Section titled “Parameters”AdapterConnectOptions
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”RealtimeProviderAdapter.connect
disconnect()
Section titled “disconnect()”disconnect():
Promise<void>
Defined in: packages/realtime-openai/src/openai-adapter.ts:459
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”RealtimeProviderAdapter.disconnect
getAudioStreams()
Section titled “getAudioStreams()”getAudioStreams():
AdapterAudioStreams
Defined in: packages/realtime-openai/src/openai-adapter.ts:463
Streams for UI metering. Never throws; absent streams are undefined.
Returns
Section titled “Returns”AdapterAudioStreams
Implementation of
Section titled “Implementation of”RealtimeProviderAdapter.getAudioStreams
injectGrounding()
Section titled “injectGrounding()”injectGrounding(
text):void
Defined in: packages/realtime-openai/src/openai-adapter.ts:495
Pushes a terse grounding string into the model’s context. The adapter
owns whatever latest-wins mechanics apply at the wire/session level
(e.g. overwriting session instructions rather than queuing utterances);
RealtimeSession additionally debounces calls into this method so the
adapter is never asked to collapse a rapid burst on its own.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”RealtimeProviderAdapter.injectGrounding
on(
handler):Unsubscribe
Defined in: packages/realtime-openai/src/openai-adapter.ts:531
Parameters
Section titled “Parameters”handler
Section titled “handler”(event) => void
Returns
Section titled “Returns”Unsubscribe
Implementation of
Section titled “Implementation of”RealtimeProviderAdapter.on
sendToolResult()
Section titled “sendToolResult()”sendToolResult(
callId,output):Promise<void>
Defined in: packages/realtime-openai/src/openai-adapter.ts:467
Sends a tool call’s result back to the model.
Parameters
Section titled “Parameters”callId
Section titled “callId”ToolCallId
output
Section titled “output”ToolResult
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”RealtimeProviderAdapter.sendToolResult
speakAssistantText()
Section titled “speakAssistantText()”speakAssistantText(
args):Promise<GreetingSpeechResult>
Defined in: packages/realtime-openai/src/openai-adapter.ts:544
Delegates provider handoff and local presentation to its package-private owner.
Parameters
Section titled “Parameters”MessageId
onPlaybackStart?
Section titled “onPlaybackStart?”() => void
signal
Section titled “signal”AbortSignal
string
Returns
Section titled “Returns”Promise<GreetingSpeechResult>
Implementation of
Section titled “Implementation of”RealtimeGreetingAdapter.speakAssistantText