--- title: A chat box with no tools id: ui-recipe-basic-chat order: 1 description: "The smallest React chat UI that works: a layout, a message, a text part, and a composer." keywords: - tanstack ai - createChatHook - chat ui - example --- This recipe is a chat UI with four components: `layout`, `message`, `text`, and `input`. It has no tools, no interrupts, and no styles. For a full TanStack Start app with your own API key, read the [Basic Chat](../../tutorials/basic-chat) tutorial. ## Server Put `OPENAI_API_KEY` in your server environment. Then add a `POST` route at `/api/chat`: ```tsx import { chat, chatParamsFromRequest, toServerSentEventsResponse, } from '@tanstack/ai' import { openaiText } from '@tanstack/ai-openai' export async function POST(request: Request) { const { messages, threadId, runId } = await chatParamsFromRequest(request) const stream = chat({ adapter: openaiText('gpt-6.1-sol'), messages, threadId, runId, }) return toServerSentEventsResponse(stream) } ``` ## Client ```tsx import { fetchServerSentEvents } from '@tanstack/ai-react' import { createChatHook } from '@tanstack/ai-react/ui' const chatOptions = { connection: fetchServerSentEvents('/api/chat'), } const { useAppChat, useChatContext } = createChatHook({ options: chatOptions, components: { input: () => { const chat = useChatContext() return (
) }, layout: ({ Messages, Input }) => ({part.content}
, fallback: () => null, }, }) export function ChatScreen() { const chat = useAppChat({ threadId: 'support-chat' }) return