RealtimeAPIClient
Methods
addEventListener
addEventListener(event: | , callback: Function
): void
Adds a handler for the specified OpenAI.Beta.RealtimeAPIEvents or OpenAI.Beta.Events event. Use only functions as handlers; anything except a function leads to the error and scenario termination when a handler is called.
Parameters
event:
Event class (i.e., OpenAI.Beta.RealtimeAPIEvents.Error)
callback:
Function
Handler function. A single parameter is passed - object with event information
Returns
type:
void
clearMediaBuffer
clearMediaBuffer(parameters: ): void
Clears the RealtimeAPI WebSocket media buffer.
Parameters
parameters:
OptionalOptional. Media buffer clearing parameters
Returns
type:
void
close
close(): void
Closes the RealtimeAPI connection (over WebSocket) or connection attempt.
Returns
type:
void
conversationItemCreate
conversationItemCreate(previousItemId: string
| null
, item: Object
, eventId: string
): void
Add a new Item to the Conversation's context, including messages, function calls, and function call responses. https://platform.openai.com/docs/api-reference/realtime_client_events/conversation/item/create.
Parameters
previousItemId:
string
The ID of the preceding item after which the new item will be inserted. If set to null, the new item will be appended to the end of the conversation. https://platform.openai.com/docs/api-reference/realtime_client_events/conversation/item/create#realtime_client_events/conversation/item/create-previous_item_id
item:
Object
The item to add to the conversation. https://platform.openai.com/docs/api-reference/realtime_client_events/conversation/item/create#realtime_client_events/conversation/item/create-item
eventId:
string
OptionalOptional. Client-generated ID used to identify this event. https://platform.openai.com/docs/api-reference/realtime_client_events/conversation/item/create#realtime_client_events/conversation/item/create-event_id
Returns
type:
void
conversationItemDelete
conversationItemDelete(itemId: string
, eventId: string
): void
Send this event when you want to remove any item from the conversation history. https://platform.openai.com/docs/api-reference/realtime_client_events/conversation/item/delete.
Parameters
itemId:
string
The ID of the item to delete. (https://platform.openai.com/docs/api-reference/realtime_client_events/conversation/item/delete#realtime_client_events/conversation/item/delete-item_id)
eventId:
string
OptionalOptional. Client-generated ID used to identify this event. https://platform.openai.com/docs/api-reference/realtime_client_events/conversation/item/delete#realtime_client_events/conversation/item/delete-event_id
Returns
type:
void
conversationItemTruncate
conversationItemTruncate(itemId: string
, contentIndex: number
, audioEndMs: number
, eventId: string
): void
Send this event to truncate a previous assistant message’s audio. https://platform.openai.com/docs/api-reference/realtime_client_events/conversation/item/truncate.
Parameters
itemId:
string
The ID of the assistant message item to truncate. https://platform.openai.com/docs/api-reference/realtime_client_events/conversation/item/truncate#realtime_client_events/conversation/item/truncate-item_id
contentIndex:
number
The index of the content part to truncate. https://platform.openai.com/docs/api-reference/realtime_client_events/conversation/item/truncate#realtime_client_events/conversation/item/truncate-content_index
audioEndMs:
number
Inclusive duration up to which audio is truncated, in milliseconds. https://platform.openai.com/docs/api-reference/realtime_client_events/conversation/item/truncate#realtime_client_events/conversation/item/truncate-audio_end_ms
eventId:
string
OptionalOptional. Client-generated ID used to identify this event. https://platform.openai.com/docs/api-reference/realtime_client_events/conversation/item/truncate#realtime_client_events/conversation/item/truncate-event_id
Returns
type:
void
id
id(): string
Returns the RealtimeAPIClient id.
Returns
type:
string
removeEventListener
removeEventListener(event: | , callback: Function
): void
Removes a handler for the specified OpenAI.Beta.RealtimeAPIEvents or OpenAI.Beta.Events event.
Parameters
event:
Event class (i.e., OpenAI.Beta.RealtimeAPIEvents.Error)
callback:
Function
OptionalOptional. Handler function. If not specified, all handler functions are removed
Returns
type:
void
responseCancel
responseCancel(eventId: string
): void
Cancels an in-progress response. https://platform.openai.com/docs/api-reference/realtime_client_events/response/cancel.
Parameters
eventId:
string
OptionalOptional. Client-generated ID used to identify this event. https://platform.openai.com/docs/api-reference/realtime_client_events/response/cancel#realtime_client_events/response/cancel-event_id
Returns
type:
void
responseCreate
responseCreate(response: Object
, eventId: string
): void
Instructs the server to create a Response, which means triggering model inference. https://platform.openai.com/docs/api-reference/realtime_client_events/response/create.
Parameters
response:
Object
The response resource. https://platform.openai.com/docs/api-reference/realtime_client_events/response/create#realtime_client_events/response/create-response. NOTE: the 'input_audio_format' parameter will be ignored
eventId:
string
OptionalOptional. Client-generated ID used to identify this event. https://platform.openai.com/docs/api-reference/realtime_client_events/response/create#realtime_client_events/response/create-event_id
Returns
type:
void
sendMediaTo
sendMediaTo(mediaUnit: , parameters: ): void
Starts sending media from the RealtimeAPI (via WebSocket) to the media unit. RealtimeAPI works in real time.
Parameters
mediaUnit:
Media unit that receives media
parameters:
OptionalOptional interaction parameters
Returns
type:
void
sessionUpdate
sessionUpdate(session: Object
, eventId: string
): void
Updates the session’s default configuration. https://platform.openai.com/docs/api-reference/realtime_client_events/session/update.
Parameters
session:
Object
Realtime session object configuration.https://platform.openai.com/docs/api-reference/realtime_client_events/session/update#realtime_client_events/session/update-session. NOTE: the 'input_audio_format' parameter will be ignored
eventId:
string
OptionalOptional. Client-generated ID used to identify this event. https://platform.openai.com/docs/api-reference/realtime_client_events/session/update#realtime_client_events/session/update-event_id
Returns
type:
void
stopMediaTo
stopMediaTo(mediaUnit: ): void
Stops sending media from the RealtimeAPI (via WebSocket) to the media unit.
Parameters
mediaUnit:
Media unit that stops receiving media
Returns
type:
void
webSocketId
webSocketId(): string
Returns the RealtimeAPI WebSocket id.
Returns
type:
string