Skip to contentSkip to content

ChatRoot API

API reference docs for the React ChatRoot component. Learn about the props, CSS, and other APIs of this exported module.

Demos

Import

import { ChatRoot } from '@mui/x-chat-headless/chat';
// or
import { ChatRoot } from '@mui/x-chat-headless';
// or
import { ChatRoot } from '@mui/x-chat';

Learn about the difference by reading this guide on minimizing bundle size.

Props

NameTypeDefaultDescription
adapter*{}-
activeConversationIdstring-
composerValuestring-
conversationsArray<{ avatarUrl?: string, id: string, lastMessageAt?: string, metadata?: ChatConversationMetadata, participants?: Array<{ avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: ChatUserMetadata, role?: any
| any
| any }>, readState?: 'read'
| 'unread', subtitle?: string, title?: string, unreadCount?: number }>
-
currentUser{ avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: ChatUserMetadata, role?: 'assistant'
| 'system'
| 'user' }
-

The local user sending messages. If omitted, derived from members by finding the entry with role === 'user'.

density'comfortable'
| 'compact'
| 'standard'
-

The vertical spacing density of chat messages. When provided, wraps descendant components with ChatDensityProvider. - 'compact' – Reduced vertical spacing between messages. - 'standard' – Default spacing. - 'comfortable' – Increased vertical spacing between messages.

initialActiveConversationIdstring-

The initial active conversation ID when uncontrolled. Ignored after initialization and when activeConversationId is provided.

initialComposerValuestring-

The initial composer value when uncontrolled. Ignored after initialization and when composerValue is provided.

initialConversationsArray<{ avatarUrl?: string, id: string, lastMessageAt?: string, metadata?: ChatConversationMetadata, participants?: Array<{ avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: ChatUserMetadata, role?: any
| any
| any }>, readState?: 'read'
| 'unread', subtitle?: string, title?: string, unreadCount?: number }>
-

The initial conversations when uncontrolled. Ignored after initialization and when conversations is provided.

initialMessagesArray<{ author?: { avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: ChatUserMetadata, role?: 'assistant'
| 'system'
| 'user' }, conversationId?: string, createdAt?: string, editedAt?: string, id: string, metadata?: ChatMessageMetadata, parts: Array<ChatDynamicToolMessagePart
| ChatFileMessagePart
| ChatReasoningMessagePart
| ChatSourceDocumentMessagePart
| ChatSourceUrlMessagePart
| ChatStepStartMessagePart
| ChatTextMessagePart
| ChatToolMessagePart
| {}>, role: 'assistant'
| 'system'
| 'user', status?: 'cancelled'
| 'error'
| 'pending'
| 'read'
| 'sending'
| 'sent'
| 'streaming', updatedAt?: string }>
-

The initial messages when uncontrolled. Ignored after initialization and when messages is provided.

localeTextPartial-
membersArray<{ avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: ChatUserMetadata, role?: 'assistant'
| 'system'
| 'user' }>
-

All participants in the chat. The current (local) user is derived as the first member with role === 'user', unless currentUser is provided explicitly.

messagesArray<{ author?: { avatarUrl?: string, displayName?: string, id: string, isOnline?: bool, metadata?: ChatUserMetadata, role?: 'assistant'
| 'system'
| 'user' }, conversationId?: string, createdAt?: string, editedAt?: string, id: string, metadata?: ChatMessageMetadata, parts: Array<ChatDynamicToolMessagePart
| ChatFileMessagePart
| ChatReasoningMessagePart
| ChatSourceDocumentMessagePart
| ChatSourceUrlMessagePart
| ChatStepStartMessagePart
| ChatTextMessagePart
| ChatToolMessagePart
| {}>, role: 'assistant'
| 'system'
| 'user', status?: 'cancelled'
| 'error'
| 'pending'
| 'read'
| 'sending'
| 'sent'
| 'streaming', updatedAt?: string }>
-
onActiveConversationChangefunc-
Signature:function(conversationId: string | undefined) => void
    onComposerValueChangefunc-
    Signature:function(value: string) => void
      onConversationsChangefunc-
      Signature:function(conversations: Array<ChatConversation>) => void
        onDatafunc-
        Signature:function(part: ChatFallbackDataMessagePart<`data-${string}`>) => void | Promise<void>
          onErrorfunc-
          Signature:function(error: ChatError) => void
            onFinishfunc-
            Signature:function(payload: ChatOnFinishPayload) => void | Promise<void>
              onMessagesChangefunc-
              Signature:function(messages: Array<ChatMessage>) => void
                onToolCallfunc-
                Signature:function(payload: ChatOnToolCallPayload) => void | Promise<void>
                  partRenderers{ dynamic-tool?: func, file?: func, reasoning?: func, source-document?: func, source-url?: func, step-start?: func, text?: func, tool?: func }-
                  slotPropsChatRootSlotProps-
                  slotsPartial-

                  See Slots API below for more details.

                  storeClassChatStoreConstructorChatStore

                  The store class to use for this provider.

                  streamFlushIntervalnumber16

                  Flush interval in milliseconds for batching rapid streaming deltas before applying them to the store.

                  variant'compact'
                  | 'default'
                  -

                  The visual layout variant of the chat. When provided, wraps descendant components with ChatVariantProvider so message and conversation components can respond to the variant. - 'default' – Standard layout with avatars, individual timestamps, and full spacing. - 'compact' – Messenger-style layout: no avatars, author + timestamp in group header, tighter spacing.

                  The component cannot hold a ref.

                  Slots

                  Slot nameClass nameDefault componentDescription
                  root

                  Source code

                  If you did not find the information in this page, consider having a look at the implementation of the component for more detail.