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>
Methods
| cancel |
Cancels an in-progress response. |
| clear |
Clears buffered input audio. |
| clear |
Clears pending output audio at the service. |
| close(number, string) | Gracefully closes the WebSocket connection. |
| commit |
Commits buffered input audio. |
| configure |
Updates supported Realtime session settings. |
| dispose() | Releases the connection. Equivalent to close(). |
| request |
Requests a new response. |
| send |
Sends raw audio bytes to the input buffer. The SDK handles base64 encoding. |
| send |
Sends a Realtime client event. |
| send |
Adds a user text item and, by default, requests a response. |
| send |
Returns a client-executed function result to the agent. |
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 Realtime 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)
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
- options
- VoiceAgentEventOptions
Returns
Promise<void>
sendEvent(VoiceAgentClientEvent, VoiceAgentSendOptions)
Sends a Realtime client 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]