ElevenLabs
ElevenLabs provides a VoxEngine client for connecting a call or media unit to the ElevenLabs Agents WebSocket API.
Use ElevenLabs.createAgentsClient(...) to create an AgentsClient for the current scenario.
Related guides
Contents
- Usage: required module import and basic flow.
- Factory functions: create the ElevenLabs Agents client.
- Methods: conversation, tools, and contextual client messages.
- Events: WebSocket media bridge events.
- AgentsEvents: ElevenLabs Agents event names and payload fields.
Usage
Add the module before using the namespace:
Create the client, bridge media, and listen for ElevenLabs Agents events.
Factory functions
createAgentsClient
Creates a new ElevenLabs.AgentsClient instance.
Parameters
Returns
createRealtimeTTSPlayer
Creates a new ElevenLabs.RealtimeTTSPlayer instance with the specified text (TTS is used to play the text). You can attach media streams later via the ElevenLabs.RealtimeTTSPlayer.sendMediaTo or VoxEngine.sendMediaBetween methods.
NOTE: this method uses 11labs initializeConnection(https://elevenlabs.io/docs/api-reference/text-to-speech/v-1-text-to-speech-voice-id-stream-input#send.initializeConnection) method internally.
Parameters
Returns
AgentsClient
Methods
addEventListener
Adds a handler for the specified ElevenLabs.AgentsEvents or ElevenLabs.Events event. Use only functions as handlers; anything except a function leads to the error and scenario termination when a handler is called.
Parameters
Returns
clearMediaBuffer
Clears the ElevenLabs WebSocket media buffer.
Parameters
Returns
clientToolResult
Result of the client tool call. https://elevenlabs.io/docs/agents-platform/api-reference/agents-platform/websocket#send.Client-Tool-Result
Parameters
Returns
close
Closes the ElevenLabs connection (over WebSocket) or connection attempt.
Parameters
This method does not accept parameters.
Returns
contextualUpdate
Allows to send non-interrupting background information to the conversation. https://elevenlabs.io/docs/agents-platform/api-reference/agents-platform/websocket#send.Contextual-Update
Parameters
Returns
conversationInitiationClientData
Defines what can be customized when starting a conversation. https://elevenlabs.io/docs/agents-platform/api-reference/agents-platform/websocket#send.Conversation-Initiation-Client-Data
Parameters
Returns
id
Returns the AgentsClient id.
Parameters
This method does not accept parameters.
Returns
removeEventListener
Removes a handler for the specified ElevenLabs.AgentsEvents or ElevenLabs.Events event.
Parameters
Returns
sendMediaTo
Starts sending media from the ElevenLabs (via WebSocket) to the media unit. ElevenLabs works in real time.
Parameters
Returns
stopMediaTo
Stops sending media from the ElevenLabs (via WebSocket) to the media unit.
Parameters
Returns
userMessage
Allows to send user text messages to the conversation. https://elevenlabs.io/docs/agents-platform/customization/events/client-to-server-events#user-messages
Parameters
Returns
webSocketId
Returns the ElevenLabs WebSocket id.
Parameters
This method does not accept parameters.
Returns
Events
These events describe audio received through the ElevenLabs WebSocket media bridge.
WebSocketMediaStarted
Triggered when the audio stream sent by a third party through an ElevenLabs WebSocket is started playing.
Event constant: Events.WebSocketMediaStarted
Payload
WebSocketMediaEnded
Triggers after the end of the audio stream sent by a third party through an ElevenLabs WebSocket (1 second of silence).
Event constant: Events.WebSocketMediaEnded
Payload
AgentsEvents
These events mirror server messages from the ElevenLabs Agents WebSocket API. The data field contains the provider event payload.
Unknown
The unknown event.
Event constant: AgentsEvents.Unknown
Payload
HTTPResponse
The HTTP response event.
Event constant: AgentsEvents.HTTPResponse
Payload
ConversationInitiationMetadata
Automatically sent when starting a conversation. Initializes conversation settings and parameters. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#conversation_initiation_metadata
Event constant: AgentsEvents.ConversationInitiationMetadata
Payload
Example data:
Ping
Health check event requiring immediate response. Used to maintain WebSocket connection. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#ping
Event constant: AgentsEvents.Ping
Payload
Example data:
UserTranscript
Contains finalized speech-to-text results. Represents complete user utterances. Used for conversation history. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#user_transcript
Event constant: AgentsEvents.UserTranscript
Payload
Example data:
AgentResponse
Contains complete agent message. Sent with first audio chunk. Used for display and history. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#agent_response
Event constant: AgentsEvents.AgentResponse
Payload
Example data:
AgentResponseCorrection
Contains truncated response after interruption. Updates displayed message. Maintains conversation accuracy. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#agent_response_correction
Event constant: AgentsEvents.AgentResponseCorrection
Payload
Example data:
Interruption
Contains event id of interrupted event. https://elevenlabs.io/docs/agents-platform/api-reference/agents-platform/websocket#receive.Interruption
Event constant: AgentsEvents.Interruption
Payload
Example data:
ContextualUpdate
Contains contextual information to be added to the conversation state. https://elevenlabs.io/docs/agents-platform/api-reference/agents-platform/websocket#receive.Contextual-Update
Event constant: AgentsEvents.ContextualUpdate
Payload
ClientToolCall
Represents a function call the agent wants the client to execute. Contains tool name, tool call ID, and parameters. Requires client-side execution of the function and sending the result back to the server. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#client_tool_call
Event constant: AgentsEvents.ClientToolCall
Payload
Example data:
VadScore
Voice Activity Detection score event. Indicates the probability that the user is speaking. Values range from 0 to 1, where higher values indicate higher confidence of speech. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#vad_score
Event constant: AgentsEvents.VadScore
Payload
InternalTentativeAgentResponse
Contains preliminary text from the agent. https://elevenlabs.io/docs/agents-platform/api-reference/agents-platform/websocket#receive.Internal-Tentative-Agent-Response
Event constant: AgentsEvents.InternalTentativeAgentResponse
Payload
Example data:
WebSocketError
The WebSocket error response event.
Event constant: AgentsEvents.WebSocketError
Payload
ConnectorInformation
Contains information about connector.
Event constant: AgentsEvents.ConnectorInformation
Payload
AgentToolResponse
Indicates when the agent has executed a tool function. Contains tool metadata and execution status. Provides visibility into agent tool usage during conversations. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#agent_tool_response
Event constant: AgentsEvents.AgentToolResponse
Payload
Example data: