VoiceAgentConnection interface

A connected, bidirectional voice-agent stream.

Supports exactly one for await iteration over server events; a second attempt throws. Exiting the loop early (break, return, or an uncaught error in the loop body) closes the connection as a side effect. Unrecognized server event types are delivered as VoiceAgentUnknownEvent without interrupting the stream. Malformed events still fail the iteration 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 live-session settings.

dispose()

Releases the connection. Equivalent to close().

requestResponse(VoiceAgentResponseOptions)

Requests a new response.

sendAudio(ArrayBuffer | Uint8Array, VoiceAgentEventOptions)

Appends base64-encoded audio bytes to the input buffer.

sendEvent(VoiceAgentClientEvent, VoiceAgentSendOptions)

Sends any generated client protocol 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 live-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)

Appends base64-encoded audio bytes to the input buffer.

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

Parameters

audio

ArrayBuffer | Uint8Array

Returns

Promise<void>

sendEvent(VoiceAgentClientEvent, VoiceAgentSendOptions)

Sends any generated client protocol 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]