Skip to content

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.

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();
  • RealtimeProviderAdapter
  • RealtimeGreetingAdapter

new OpenAIAdapter(options): OpenAIAdapter

Defined in: packages/realtime-openai/src/openai-adapter.ts:228

OpenAIAdapterOptions

OpenAIAdapter

readonly observations: 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.

RealtimeProviderAdapter.observations

activateAudio(): void

Defined in: packages/realtime-openai/src/openai-adapter.ts:539

Unlocks retained Web Audio activation in the initiating gesture.

void

RealtimeGreetingAdapter.activateAudio


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.

AdapterConnectOptions

Promise<void>

RealtimeProviderAdapter.connect


disconnect(): Promise<void>

Defined in: packages/realtime-openai/src/openai-adapter.ts:459

Promise<void>

RealtimeProviderAdapter.disconnect


getAudioStreams(): AdapterAudioStreams

Defined in: packages/realtime-openai/src/openai-adapter.ts:463

Streams for UI metering. Never throws; absent streams are undefined.

AdapterAudioStreams

RealtimeProviderAdapter.getAudioStreams


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.

string

void

RealtimeProviderAdapter.injectGrounding


on(handler): Unsubscribe

Defined in: packages/realtime-openai/src/openai-adapter.ts:531

(event) => void

Unsubscribe

RealtimeProviderAdapter.on


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.

ToolCallId

ToolResult

Promise<void>

RealtimeProviderAdapter.sendToolResult


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.

MessageId

() => void

AbortSignal

string

Promise<GreetingSpeechResult>

RealtimeGreetingAdapter.speakAssistantText