RealtimeTransportLayer
此内容尚不支持你的语言。
The transport layer is the layer that handles the connection to the model and the communication with the model.
Extends
Section titled “Extends”EventEmitter<RealtimeTransportEventTypes>
Properties
Section titled “Properties”readonly muted: boolean | null;Whether the input audio track is currently muted null if the muting is not handled by the transport layer
status
Section titled “status”status: "connecting" | "connected" | "disconnected" | "disconnecting";Methods
Section titled “Methods”addImage()
Section titled “addImage()”addImage(image, options?): void;Sends an image to the model
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
The image to send |
|
|
{ |
Additional options |
|
|
|
Whether to trigger a response from the model |
Returns
Section titled “Returns”void
close()
Section titled “close()”close(): void;Closes the connection to the model
Returns
Section titled “Returns”void
connect()
Section titled “connect()”connect(options): Promise<void>;Establishes the connection to the model and keeps the connection alive
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
The options for the connection |
Returns
Section titled “Returns”Promise<void>
emit()
Section titled “emit()”emit<K>(type, ...args): boolean;Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
|
|
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
… |
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”EventEmitter.emitgetDefaultAudioFormat()?
Section titled “getDefaultAudioFormat()?”optional getDefaultAudioFormat(): RealtimeAudioFormat;The default format for both input and output audio. RealtimeSession calls this when constructed, before applying caller configuration. Transports that omit this hook retain the session’s PCM 24 kHz defaults. Explicit caller formats take precedence over this default; partial audio settings retain it for directions without an explicit format.
Returns
Section titled “Returns”interrupt()
Section titled “interrupt()”interrupt(): void;Interrupts the current turn. Used for example when a guardrail is triggered
Returns
Section titled “Returns”void
mute()
Section titled “mute()”mute(muted): void;Mutes the input audio track
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
Whether to mute the input audio track |
Returns
Section titled “Returns”void
off<K>(type, listener): EventEmitter<RealtimeTransportEventTypes>;Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
|
|
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
(… |
Returns
Section titled “Returns”EventEmitter<RealtimeTransportEventTypes>
Inherited from
Section titled “Inherited from”EventEmitter.offon<K>(type, listener): EventEmitter<RealtimeTransportEventTypes>;Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
|
|
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
(… |
Returns
Section titled “Returns”EventEmitter<RealtimeTransportEventTypes>
Inherited from
Section titled “Inherited from”EventEmitter.ononce()
Section titled “once()”once<K>(type, listener): EventEmitter<RealtimeTransportEventTypes>;Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
|
|
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
(… |
Returns
Section titled “Returns”EventEmitter<RealtimeTransportEventTypes>
Inherited from
Section titled “Inherited from”EventEmitter.oncerequestResponse()?
Section titled “requestResponse()?”optional requestResponse(response?): void;Requests a new response for the current conversation turn. Implementations may defer the
underlying response.create until the server has fully finished the prior response.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
Optional one-off response override payload. |
Returns
Section titled “Returns”void
resetHistory()
Section titled “resetHistory()”resetHistory(oldHistory, newHistory): void;Resets the conversation history / context to a specific state
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
The history that is currently stored on the session. |
|
|
|
The history you want the session to use going forward. |
Returns
Section titled “Returns”void
sendAudio()
Section titled “sendAudio()”sendAudio(audio, options): void;Sends a raw audio buffer to the model
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
The audio buffer to send |
|
|
{ |
Additional options |
|
|
|
Whether to commit the audio buffer to the model. If the model does not do turn detection, this can be used to indicate the turn is completed. |
Returns
Section titled “Returns”void
sendEvent()
Section titled “sendEvent()”sendEvent(event): void;Sends a raw event to the model
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
The event to send |
Returns
Section titled “Returns”void
sendFunctionCallOutput()
Section titled “sendFunctionCallOutput()”sendFunctionCallOutput( toolCall, output, startResponse): void;Sends a function call output to the model
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
The tool call to send |
|
|
|
|
The output of the tool call |
|
|
|
‐ |
Returns
Section titled “Returns”void
sendMcpResponse()
Section titled “sendMcpResponse()”sendMcpResponse( approvalRequest, approved, reason?): void;Sends a response for an MCP tool call
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
{ |
The approval request to respond to |
|
|
|
‐ |
|
|
|
‐ |
|
|
|
‐ |
|
|
|
‐ |
|
|
|
‐ |
|
|
|
‐ |
|
|
|
Whether the tool call was approved or rejected |
|
|
|
Optional rejection text for the provider/model. |
Returns
Section titled “Returns”void
sendMessage()
Section titled “sendMessage()”sendMessage( message, otherEventData, options?): void;Sends a text message to the model
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
The message to send |
|
|
|
Additional event data, will be merged into the event |
|
|
{ |
Additional options |
|
|
|
Whether to trigger a response from the model |
Returns
Section titled “Returns”void
updateSessionConfig()
Section titled “updateSessionConfig()”updateSessionConfig(config): void;Sends an updated session configuration to the model. Used to update for example the model instructions during a handoff
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
The new session config |
Returns
Section titled “Returns”void