VoiceAgentConnection interface

A Realtime voice session.

Read server events with one for await loop. A second iterator throws. Leaving the loop closes the connection. Unrecognized event types arrive as VoiceAgentUnknownEvent; malformed events fail with a protocol error.

Extends

AsyncIterable<VoiceAgentRealtimeEvent>

Properties

closed

Resolves once the connection is closed.

state

Current connection state.

Methods

cancelResponse(VoiceAgentCancelResponseOptions)

Cancels an in-progress response.

clearInputAudio(VoiceAgentEventOptions)

Clears buffered input audio.

clearOutputAudio(VoiceAgentEventOptions)

Clears pending output audio at the service.

close(number, string)

Gracefully closes the WebSocket connection.

commitAudio(VoiceAgentEventOptions)

Commits buffered input audio.

configureSession(VoiceAgentSessionUpdateConfig, VoiceAgentSessionUpdateOptions)

Updates supported Realtime session settings.

dispose()

Releases the connection. Equivalent to close().

requestResponse(VoiceAgentResponseOptions)

Requests a new response.

sendAudio(ArrayBuffer | Uint8Array, VoiceAgentEventOptions)

Sends raw audio bytes to the input buffer. The SDK handles base64 encoding.

sendEvent(VoiceAgentClientEvent, VoiceAgentSendOptions)

Sends a Realtime client event.

sendText(string, VoiceAgentSendTextOptions)

Adds a user text item and, by default, requests a response.

sendToolOutput(string, string, VoiceAgentSendToolOutputOptions)

Returns a client-executed function result to the agent.

Inherited Methods

[asyncIterator]()

Property Details

closed

Resolves once the connection is closed.

closed: Promise<VoiceAgentCloseResult>

Property Value

state

Current connection state.

state: VoiceAgentConnectionState

Property Value

Method Details

cancelResponse(VoiceAgentCancelResponseOptions)

Cancels an in-progress response.

function cancelResponse(options?: VoiceAgentCancelResponseOptions): Promise<void>

Parameters

Returns

Promise<void>

clearInputAudio(VoiceAgentEventOptions)

Clears buffered input audio.

function clearInputAudio(options?: VoiceAgentEventOptions): Promise<void>

Parameters

Returns

Promise<void>

clearOutputAudio(VoiceAgentEventOptions)

Clears pending output audio at the service.

function clearOutputAudio(options?: VoiceAgentEventOptions): Promise<void>

Parameters

Returns

Promise<void>

close(number, string)

Gracefully closes the WebSocket connection.

function close(code?: number, reason?: string): Promise<void>

Parameters

code

number

reason

string

Returns

Promise<void>

commitAudio(VoiceAgentEventOptions)

Commits buffered input audio.

function commitAudio(options?: VoiceAgentEventOptions): Promise<void>

Parameters

Returns

Promise<void>

configureSession(VoiceAgentSessionUpdateConfig, VoiceAgentSessionUpdateOptions)

Updates supported Realtime session settings.

function configureSession(session: VoiceAgentSessionUpdateConfig, options?: VoiceAgentSessionUpdateOptions): Promise<void>

Parameters

Returns

Promise<void>

dispose()

Releases the connection. Equivalent to close().

function dispose(): Promise<void>

Returns

Promise<void>

requestResponse(VoiceAgentResponseOptions)

Requests a new response.

function requestResponse(options?: VoiceAgentResponseOptions): Promise<void>

Parameters

Returns

Promise<void>

sendAudio(ArrayBuffer | Uint8Array, VoiceAgentEventOptions)

Sends raw audio bytes to the input buffer. The SDK handles base64 encoding.

function sendAudio(audio: ArrayBuffer | Uint8Array, options?: VoiceAgentEventOptions): Promise<void>

Parameters

audio

ArrayBuffer | Uint8Array

Returns

Promise<void>

sendEvent(VoiceAgentClientEvent, VoiceAgentSendOptions)

Sends a Realtime client event.

function sendEvent(event: VoiceAgentClientEvent, options?: VoiceAgentSendOptions): Promise<void>

Parameters

Returns

Promise<void>

sendText(string, VoiceAgentSendTextOptions)

Adds a user text item and, by default, requests a response.

function sendText(text: string, options?: VoiceAgentSendTextOptions): Promise<void>

Parameters

text

string

Returns

Promise<void>

sendToolOutput(string, string, VoiceAgentSendToolOutputOptions)

Returns a client-executed function result to the agent.

function sendToolOutput(callId: string, output: string, options?: VoiceAgentSendToolOutputOptions): Promise<void>

Parameters

callId

string

output

string

Returns

Promise<void>

Inherited Method Details

[asyncIterator]()

function [asyncIterator](): AsyncIterator<VoiceAgentRealtimeEvent, any, any>

Returns

AsyncIterator<VoiceAgentRealtimeEvent, any, any>

Inherited From AsyncIterable.[asyncIterator]