Chat and Streaming Interfaces

Render streamed tokens, markdown, code and tool activity in a responsive chat UI with stop, retry and edit controls.

Intermediate · about 6 hours · difficulty 3/5

Learn first: Streaming Responses

The chat box looks simple but hides many details that decide whether a product feels polished or broken.

Streaming on the client

  • Consume server-sent events or a streaming fetch body and append chunks to the message as they arrive.
  • Render markdown incrementally without flicker, including code blocks with syntax highlighting and copy buttons. Sanitize HTML, because model output is untrusted.
  • Keep the view scrolled to the bottom unless the user has scrolled up to read.
  • Show tool and agent activity ("Searching documents...", "Running query...") so long waits feel purposeful.

Essential controls

  • Stop generation, which should abort the upstream model request too, not just hide the output.
  • Retry / regenerate, edit and resend a previous message, and copy.
  • Clear loading, error and rate-limit states with a way to recover.
  • Attachments for files and images with progress and size limits.

Libraries

The Vercel AI SDK provides React, Vue and Svelte hooks for streaming chat and tool UIs; assistant-ui and similar kits offer ready components. You can also build it yourself with fetch and a markdown renderer.

Beyond chat

Chat is not always the best interface. Inline suggestions, one-click actions, forms that the model pre-fills and side panels often fit a workflow better than an empty text box.

Good enough to move on

You can build a chat UI that streams markdown safely, shows tool progress, supports stop, retry and edit, and handles network errors without losing the conversation.

Key concepts

  • Consuming SSE on the client
  • Incremental markdown rendering
  • Sanitizing model output
  • Stop, retry and edit controls
  • Tool activity indicators
  • Vercel AI SDK UI hooks
  • Non-chat AI interfaces

Mini project

Build a React chat interface that streams responses from your backend, renders markdown and code safely, shows when a tool is running, and supports stop, regenerate and editing earlier messages.

Check yourself

Why must the Stop button cancel the request on the server, not just stop rendering on the client?

Free resources