Skip to content

OpenAIRealtimeBase

The transport layer is the layer that handles the connection to the model and the communication with the model.

new OpenAIRealtimeBase(options): OpenAIRealtimeBase
Parameter Type

options

OpenAIRealtimeBaseOptions

OpenAIRealtimeBase

EventEmitterDelegate<OpenAIRealtimeEventTypes>.constructor
abstract readonly muted: null | boolean;

Whether the input audio track is currently muted null if the muting is not handled by the transport layer

RealtimeTransportLayer.muted

set _tracingConfig(tracingConfig): void

Sets the internal tracing config. This is used to track the tracing config that has been set during the session.create event.

Parameter Type

tracingConfig

null | RealtimeTracingConfig

void


get currentModel(): OpenAIRealtimeModels

The current model that is being used by the transport layer.

OpenAIRealtimeModels

set currentModel(model): void

The current model that is being used by the transport layer. Note: The model cannot be changed mid conversation.

Parameter Type

model

OpenAIRealtimeModels

void


get abstract status(): "connecting" | "connected" | "disconnected" | "disconnecting"

"connecting" | "connected" | "disconnected" | "disconnecting"

RealtimeTransportLayer.status

abstract close(): void

Closes the connection to the model

void

RealtimeTransportLayer.close


abstract connect(options): Promise<void>

Establishes the connection to the model and keeps the connection alive

Parameter Type Description

options

RealtimeTransportLayerConnectOptions

The options for the connection

Promise<void>

RealtimeTransportLayer.connect


emit<K>(type, ...args): boolean
Type Parameter

K extends keyof RealtimeTranportEventTypes

Parameter Type

type

K

args

OpenAIRealtimeEventTypes[K]

boolean

RealtimeTransportLayer.emit

EventEmitterDelegate.emit

abstract interrupt(): void

Interrupts the current turn. Used for example when a guardrail is triggered

void

RealtimeTransportLayer.interrupt


abstract mute(muted): void

Mutes the input audio track

Parameter Type Description

muted

boolean

Whether to mute the input audio track

void

RealtimeTransportLayer.mute


off<K>(type, listener): EventEmitter<EventTypes>
Type Parameter

K extends keyof RealtimeTranportEventTypes

Parameter Type

type

K

listener

(…args) => void

EventEmitter<EventTypes>

RealtimeTransportLayer.off

EventEmitterDelegate.off

on<K>(type, listener): EventEmitter<EventTypes>
Type Parameter

K extends keyof RealtimeTranportEventTypes

Parameter Type

type

K

listener

(…args) => void

EventEmitter<EventTypes>

RealtimeTransportLayer.on

EventEmitterDelegate.on

once<K>(type, listener): EventEmitter<EventTypes>
Type Parameter

K extends keyof RealtimeTranportEventTypes

Parameter Type

type

K

listener

(…args) => void

EventEmitter<EventTypes>

RealtimeTransportLayer.once

EventEmitterDelegate.once

resetHistory(oldHistory, newHistory): void

Reset the history of the conversation. This will create a diff between the old and new history and send the necessary events to the Realtime API to update the history.

Parameter Type Description

oldHistory

RealtimeItem[]

The old history of the conversation.

newHistory

RealtimeItem[]

The new history of the conversation.

void

RealtimeTransportLayer.resetHistory


sendAudio(audio, options): void

Send an audio buffer to the Realtime API. If { commit: true } is passed, the audio buffer will be committed and the model will start processing it. This is necessary if you have disabled turn detection / voice activity detection (VAD).

Parameter Type Description

audio

ArrayBuffer

The audio buffer to send.

options

{ commit: boolean; }

The options for the audio buffer.

options.commit?

boolean

void

RealtimeTransportLayer.sendAudio


abstract sendEvent(event): void

Sends a raw event to the model

Parameter Type Description

event

RealtimeClientMessage

The event to send

void

RealtimeTransportLayer.sendEvent


sendFunctionCallOutput(
toolCall,
output,
startResponse): void

Send the output of a function call to the Realtime API.

Parameter Type Default value Description

toolCall

TransportToolCallEvent

undefined

The tool call to send the output for.

output

string

undefined

The output of the function call.

startResponse

boolean

true

Whether to start a new response after sending the output.

void

RealtimeTransportLayer.sendFunctionCallOutput


sendMessage(message, otherEventData): void

Send a message to the Realtime API. This will create a new item in the conversation and trigger a response.

Parameter Type Description

message

RealtimeUserInput

The message to send.

otherEventData

Record<string, any>

Additional event data to send.

void

RealtimeTransportLayer.sendMessage


updateSessionConfig(config): void

Updates the session config. This will merge it with the current session config with the default values and send it to the Realtime API.

Parameter Type Description

config

Partial<RealtimeSessionConfig>

The session config to update.

void

RealtimeTransportLayer.updateSessionConfig