Hello! I am styled using your active Material UI theme. Try sending a message.
Chat - Basic AI chat
Render a single-conversation ChatBox seeded with an adapter, a conversation, and an initial message.
The ChatBox component renders with seeded conversation state from @mui/x-chat.
ChatBoxrendering a single conversation without a conversation listinitialConversationsandinitialMessagesfor initial stateinitialActiveConversationIdto open the conversation immediatelysxfor sizing the container
The demo below shows the resulting ChatBox surface:
Press Enter to start editing
Seeding initial state
The smallest working @mui/x-chat surface needs three pieces of initial state:
- An
adapterthat implementssendMessage - An
initialConversationsarray with at least one conversation - An
initialActiveConversationIdthat matches one of those conversations
Only adapter is required by the component API.
The conversation props in this example are there so the thread opens with seeded title and message history.
Implementing the adapter
The demo uses a local echo adapter that echoes the user message back as a streaming response. In a real application, replace it with an adapter that calls your backend:
const adapter: ChatAdapter = {
async sendMessage({ message, signal }) {
const response = await fetch('/api/chat', {
method: 'POST',
body: JSON.stringify({ message }),
signal,
});
return response.body; // ReadableStream<ChatMessageChunk>
},
};
Tips for setup
- Keep the container height explicit so the message list and composer render correctly.
- Omitting
initialConversationsrenders a blank thread surface until messages are loaded or sent. - Omitting
initialActiveConversationIdkeeps the built-in thread surface mounted, but there is no active conversation selected. - The conversation list UI stays off by default.
Enable it with
features={{ conversationList: true }}.
See also
- See Multi-conversation for details on adding a conversation sidebar.
- See Customization for details on theme overrides, slots, and slot props.