Skip to main content
The @xuna-ai/react package gives you hooks and providers to build completely custom voice interfaces in React. Use it when you need control the widget doesn’t provide — custom UI, client-side tools, dynamic overrides, or fine-grained state management.

Installation

@xuna-ai/react re-exports everything from @xuna-ai/client, so you only need one dependency.

Minimal example

Wrap your app in ConversationProvider, then use hooks inside it to start and stop sessions.

ConversationProvider

Place ConversationProvider at the root of any component tree that needs access to conversation state. It accepts the following props:

Hooks

Use granular hooks to avoid unnecessary re-renders. Each hook subscribes only to the state it needs.

useConversationControls

Session lifecycle and messaging actions.

useConversationStatus

Current connection state.

useConversationInput

Microphone mute control.

useConversationMode

Whether the agent is speaking or listening.

useConversationFeedback

Submit session feedback.

useConversationClientTool

Register a client tool from inside a component. The tool name must match what you configured for the agent in the dashboard.

useConversation

Combines all hooks in one. Convenient for simple components, but causes more re-renders than using granular hooks.
Prefer the granular hooks (useConversationControls, useConversationStatus, etc.) in performance-sensitive components. Use useConversation only in small or infrequent-rendering components.

startSession options

Pass options to startSession to control how the session connects.

Authenticating private agents

If your agent is private, generate a credential on your server and pass it to startSession. Choose WebSocket (signed URL) or WebRTC (conversation token) based on your stack.
Server
Client
Never include your XUNA_AI_API_KEY in client-side code. Always call the XUNA AI API from your server.

Client tools

Client tools let the agent call functions in your React app during a conversation — for example, to display information, submit a form, or navigate the UI. Define them on ConversationProvider or register them with useConversationClientTool.
The return value is sent back to the agent as the tool result.

Overrides

Pass overrides to startSession to customize agent behavior for a specific session without changing the agent’s dashboard configuration.

Server location

By default, conversation servers are located in the US. Set serverLocation on ConversationProvider to use a different region.

Next steps

  • To deploy without a custom UI, use the widget instead.
  • For mobile apps, see the Mobile SDKs page.
  • To build a fully custom integration outside React, use the WebSocket API.