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>
Methods
Inherited Methods
| [async |
Property Details
closed
Resolves once the connection is closed.
closed: Promise<VoiceAgentCloseResult>
Property Value
Promise<VoiceAgentCloseResult>
state
Method Details
cancelResponse(VoiceAgentCancelResponseOptions)
Cancels an in-progress response.
function cancelResponse(options?: VoiceAgentCancelResponseOptions): Promise<void>
Parameters
- options
- VoiceAgentCancelResponseOptions
Returns
Promise<void>
clearInputAudio(VoiceAgentEventOptions)
Clears buffered input audio.
function clearInputAudio(options?: VoiceAgentEventOptions): Promise<void>
Parameters
- options
- VoiceAgentEventOptions
Returns
Promise<void>
clearOutputAudio(VoiceAgentEventOptions)
Clears pending output audio at the service.
function clearOutputAudio(options?: VoiceAgentEventOptions): Promise<void>
Parameters
- options
- VoiceAgentEventOptions
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
- options
- VoiceAgentEventOptions
Returns
Promise<void>
configureSession(VoiceAgentSessionUpdateConfig, VoiceAgentSessionUpdateOptions)
Updates supported live-session settings.
function configureSession(session: VoiceAgentSessionUpdateConfig, options?: VoiceAgentSessionUpdateOptions): Promise<void>
Parameters
- session
- VoiceAgentSessionUpdateConfig
- options
- VoiceAgentSessionUpdateOptions
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
- options
- VoiceAgentResponseOptions
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
- options
- VoiceAgentEventOptions
Returns
Promise<void>
sendEvent(VoiceAgentClientEvent, VoiceAgentSendOptions)
Sends any generated client protocol event.
function sendEvent(event: VoiceAgentClientEvent, options?: VoiceAgentSendOptions): Promise<void>
Parameters
- event
- VoiceAgentClientEvent
- options
- VoiceAgentSendOptions
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
- options
- VoiceAgentSendTextOptions
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
- options
- VoiceAgentSendToolOutputOptions
Returns
Promise<void>
Inherited Method Details
[asyncIterator]()
function [asyncIterator](): AsyncIterator<VoiceAgentRealtimeEvent, any, any>
Returns
AsyncIterator<VoiceAgentRealtimeEvent, any, any>
Inherited From AsyncIterable.[asyncIterator]