React SDK
ElevenAgents SDK: deploy customized, interactive voice agents in minutes.
ElevenAgents SDK: deploy customized, interactive voice agents in minutes.
Refer to the ElevenAgents overview for an explanation of how ElevenAgents works.
Install the package in your project through package manager.
Upgrading from an earlier version? Run npx skills add elevenlabs/packages to install the
elevenlabs:sdk-migration skill for your AI coding agent, which automates import changes,
ConversationProvider wrapping, and API updates.
@elevenlabs/react re-exports everything from @elevenlabs/client, so you don’t need to install
both packages.
Here is a minimal working example that connects to an agent and lets the user start and end a voice conversation:
The sections below explain each part in detail.
All conversation hooks must be used within a ConversationProvider. Wrap your app (or the relevant subtree) with this provider.
The provider accepts the same options as useConversation — including callbacks, client tools, overrides, and server location — so you can configure them at the provider level rather than in each hook consumer.
The provider supports isMuted and onMutedChange props for controlled mute state management, allowing you to persist mute state externally (e.g. across sessions).
A convenience React hook that combines all granular hooks into a single return value. Requires a ConversationProvider ancestor.
For better render performance, consider using the granular hooks instead.
useConversation triggers a re-render on any state change, while the granular hooks only
re-render when their specific slice of state changes.
Note that ElevenAgents requires microphone access for voice conversations. Consider explaining and allowing access in your app’s UI before the conversation starts.
The hook can be optionally initialized with options. These can also be passed at the ConversationProvider level.
Options include:
"us", "eu-residency", "in-residency", "global"). Defaults to "us".Client tools are a way to enable agent to invoke client-side functionality. This can be used to trigger actions in the client, such as opening a modal or doing an API call on behalf of the user.
Client tools definition is an object of functions, and needs to be identical with your configuration within the ElevenLabs UI, where you can name and describe different tools, as well as set up the parameters passed by the agent.
If the function returns a value, it is passed back to the agent as a response.
The tool must be explicitly set to block the conversation in the ElevenLabs UI for the agent to await and react to the response. Otherwise, the agent assumes success and continues the conversation.
For a more React-idiomatic approach to registering client tools, see useConversationClientTool.
You may choose to override various settings of the conversation and set them dynamically based other user interactions.
We support overriding various settings. These settings are optional and can be used to customize the conversation experience.
The following settings are available:
If your agent is configured to run in text-only mode, i.e. it does not send or receive audio messages, you can use this flag to use a lighter version of the conversation. In that case, the user will not be asked for microphone permissions and no audio context will be created.
You can control certain aspects of the conversation state directly through the hook options:
You can specify which ElevenLabs server region to connect to. For more information see the data residency guide.
The startSession method establishes the connection and starts using the microphone to communicate with the ElevenLabs Agents agent. The method accepts an options object, with signedUrl, conversationToken, or agentId being required.
The Agent ID can be acquired through ElevenLabs UI.
We also recommended passing in your own end user IDs to map conversations to your users.
The connection type is automatically inferred based on the conversation mode. Voice conversations
use WebRTC and text-only conversations use WebSocket by default. You can still explicitly specify
connectionType if needed.
For public agents (i.e. agents that don’t have authentication enabled), only the agentId is required.
If the conversation requires authorization, use the REST API to generate signed links for a WebSocket connection or a conversation token for a WebRTC connection.
startSession returns a promise resolving a conversationId. The value is a globally unique conversation ID you can use to identify separate conversations.
A method to manually end the conversation. The method will disconnect and end the conversation.
Sets the output volume of the conversation. Accepts an object with a volume field between 0 and 1.
Sends a text message to the agent.
Can be used to let the user type in the message instead of using the microphone. Unlike sendContextualUpdate, this will be treated as a user message and will prompt the agent to take its turn in the conversation.
Sends contextual information to the agent that won’t trigger a response.
Provide feedback on the conversation quality. This helps improve the agent’s performance.
Notifies the agent about user activity to prevent interruptions. Useful for when the user is actively using the app and the agent should pause speaking, i.e. when the user is typing in a chat.
The agent will pause speaking for ~2 seconds after receiving this signal.
Switch the audio input device during an active voice conversation. This method is only available for voice conversations.
Switch the audio output device during an active voice conversation. This method is only available for voice conversations.
Device switching only works for voice conversations. If no specific deviceId is provided, the
browser will use its default device selection. You can enumerate available devices using the
MediaDevices.enumerateDevices()
API.
Returns the current conversation ID.
Methods that return the current input/output volume levels (0-1 scale).
Methods that return Uint8Arrays containing the current input/output frequency data. See AnalyserNode.getByteFrequencyData for more information.
These methods are only available for voice conversations. In WebRTC mode the audio is hardcoded to
use pcm_48000, meaning any visualization using the returned data might show different patterns
to WebSocket connections.
Sends approval result for MCP (Model Context Protocol) tool calls.
In addition to the methods above, useConversation returns the following reactive state:
"disconnected", "connecting", "connected")."speaking" or "listening").For better render performance, use these hooks instead of useConversation. Each hook subscribes to only its specific slice of state, so components only re-render when the data they consume changes.
All granular hooks require a ConversationProvider ancestor.
Returns action methods for controlling the conversation. This hook does not cause re-renders since it only provides stable function references.
Returns the current connection status and optional status message.
Returns mute state and a setter for toggling the microphone.
Returns speaking/listening state for the agent.
Returns feedback availability and a method to submit feedback.
Returns the raw conversation instance. This is an escape hatch for advanced use cases where you need direct access to the underlying VoiceConversation or TextConversation object.
A hook for dynamically registering client tools from React components. Tools are automatically unregistered when the component unmounts.
This is useful when a tool’s handler needs access to component state or props that aren’t available at the provider level.
The hook always uses the latest closure value of the handler, so you don’t need to worry about stale state.