Skip to content

OpenAIRealtimeSIP

Transport layer that connects to an existing SIP-initiated Realtime call via call ID.

new OpenAIRealtimeSIP(options): OpenAIRealtimeSIP;
Parameter Type

options

OpenAIRealtimeWebSocketOptions

OpenAIRealtimeSIP

OpenAIRealtimeWebSocket.constructor

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

RealtimeTracingConfig | null

void

OpenAIRealtimeWebSocket._tracingConfig


get connectionState(): WebSocketState;

The current connection state of the WebSocket connection.

WebSocketState

OpenAIRealtimeWebSocket.connectionState


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

OpenAIRealtimeWebSocket.currentModel


get muted(): null;

Always returns null as the WebSocket transport layer does not handle muting. Instead, this should be handled by the client by not triggering the sendAudio method.

null

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

OpenAIRealtimeWebSocket.muted


get status(): "connecting" | "connected" | "disconnected";

The current status of the WebSocket connection.

"connecting" | "connected" | "disconnected"

OpenAIRealtimeWebSocket.status

_cancelResponse(): void;

Send a cancel response event to the Realtime API. This is used to cancel an ongoing response that the model is currently generating.

void

OpenAIRealtimeWebSocket._cancelResponse


_interrupt(elapsedTime, cancelOngoingResponse): void;

Do NOT call this method directly. Call interrupt() instead for proper interruption handling.

This method is used to send the right events to the API to inform the model that the user has interrupted the response. It might be overridden/extended by an extended transport layer. See the TwilioRealtimeTransportLayer for an example.

Parameter Type Default value Description

elapsedTime

number

undefined

The elapsed time since the response started.

cancelOngoingResponse

boolean

true

void

OpenAIRealtimeWebSocket._interrupt


addImage(image, options): void;

Sends an image to the model

Parameter Type Description

image

string

The image to send

options

{ triggerResponse?: boolean; }

Additional options

options.triggerResponse?

boolean

Whether to trigger a response from the model

void

OpenAIRealtimeWebSocket.addImage


buildSessionPayload(config): RealtimeSessionPayload;

Build the payload object expected by the Realtime API when creating or updating a session.

The helper centralises the conversion from camelCase runtime config to the snake_case payload required by the Realtime API so transports that need a one-off payload (for example SIP call acceptance) can reuse the same logic without duplicating private state.

Parameter Type Description

config

Partial<RealtimeSessionConfig>

The session config to merge with defaults.

RealtimeSessionPayload

OpenAIRealtimeWebSocket.buildSessionPayload


close(): void;

Close the WebSocket connection.

This will also reset any internal connection tracking used for interruption handling.

void

OpenAIRealtimeWebSocket.close


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>

OpenAIRealtimeWebSocket.connect


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

K extends keyof RealtimeTransportEventTypes

Parameter Type

type

K

args

OpenAIRealtimeEventTypes[K]

boolean

OpenAIRealtimeWebSocket.emit


interrupt(cancelOngoingResponse): void;

Interrupt the ongoing response. This method is triggered automatically by the client when voice activity detection (VAD) is enabled (default) as well as when an output guardrail got triggered.

You can also call this method directly if you want to interrupt the conversation for example based on an event in the client.

Parameter Type Default value

cancelOngoingResponse

boolean

true

void

OpenAIRealtimeWebSocket.interrupt


mute(_muted): never;

Will throw an error as the WebSocket transport layer does not support muting.

Parameter Type

_muted

boolean

never

OpenAIRealtimeWebSocket.mute


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

K extends keyof RealtimeTransportEventTypes

Parameter Type

type

K

listener

(…args) => void

EventEmitter<EventTypes>

OpenAIRealtimeWebSocket.off


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

K extends keyof RealtimeTransportEventTypes

Parameter Type

type

K

listener

(…args) => void

EventEmitter<EventTypes>

OpenAIRealtimeWebSocket.on


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

K extends keyof RealtimeTransportEventTypes

Parameter Type

type

K

listener

(…args) => void

EventEmitter<EventTypes>

OpenAIRealtimeWebSocket.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

OpenAIRealtimeWebSocket.resetHistory


sendAudio(_audio, _options): never;

Send an audio buffer to the Realtime API. This is used for your client to send audio to the model to respond.

Parameter Type

_audio

ArrayBuffer

_options

{ commit?: boolean; }

_options.commit?

boolean

never

OpenAIRealtimeWebSocket.sendAudio


sendEvent(event): void;

Send an event to the Realtime API. This will stringify the event and send it directly to the API. This can be used if you want to take control over the connection and send events manually.

Parameter Type Description

event

RealtimeClientMessage

The event to send.

void

OpenAIRealtimeWebSocket.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

OpenAIRealtimeWebSocket.sendFunctionCallOutput


sendMcpResponse(approvalRequest, approved): void;

Sends a response for an MCP tool call

Parameter Type Description

approvalRequest

{ approved?: boolean | null; arguments: Record<string, any>; itemId: string; name: string; serverLabel: string; type: "mcp_approval_request"; }

The approval request to respond to

approvalRequest.approved?

boolean | null

approvalRequest.arguments

Record<string, any>

approvalRequest.itemId

string

approvalRequest.name

string

approvalRequest.serverLabel

string

approvalRequest.type

"mcp_approval_request"

approved

boolean

Whether the tool call was approved or rejected

void

OpenAIRealtimeWebSocket.sendMcpResponse


sendMessage(
message,
otherEventData,
__namedParameters): 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.

__namedParameters

{ triggerResponse?: boolean; }

__namedParameters.triggerResponse?

boolean

void

OpenAIRealtimeWebSocket.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

OpenAIRealtimeWebSocket.updateSessionConfig


static buildInitialConfig<TBaseContext>(
agent,
options,
overrides): Promise<RealtimeSessionPayload>;

Build the initial session payload for a SIP-attached session, matching the config that a RealtimeSession would send on connect.

This enables SIP deployments to accept an incoming call with a payload that already reflects the active agent’s instructions, tools, prompt, and tracing metadata without duplicating the session logic outside of the SDK. The returned object structurally matches the REST CallAcceptParams interface, so it can be forwarded directly to openai.realtime.calls.accept(...).

Type Parameter Default type

TBaseContext

unknown

Parameter Type Description

agent

| RealtimeAgent<TBaseContext> | RealtimeAgent<RealtimeContextData<TBaseContext>>

The starting agent used to seed the session instructions, tools, and prompt.

options

Partial<RealtimeSessionOptions<TBaseContext>>

Optional session options that mirror the ones passed to the RealtimeSession constructor.

overrides

Partial<RealtimeSessionConfig>

Additional config overrides applied on top of the session options.

Promise<RealtimeSessionPayload>