unlisted workshop

    Day 2: Persistence

    Matt Pocock
    Matt Pocock

    Using useChat from Vercel AI SDK makes it easy to get a basic chatbot up and running. But turning that quick prototype into a fully functional, persistent chat product is where most developers get stuck.

    How do you save user and assistant messages as they stream in? What’s the right moment to create and store a new chat ID? How do you support routing by chatId and keep your UI in sync when the chat history changes?

    This workshop is all about bridging that gap—taking your chat from demo to durable, with backend persistence, real-time updates, and solid routing.

    You will:

    • Build a POST /api/chat endpoint using createDataStreamResponse to stream completions from OpenAI
    • Use Drizzle to create a new chat record and return the generated chatId over the stream itself
    • Automatically redirect users to the new /chat/:chatId route once it’s available
    • Save each user and assistant message to your database as it streams in
    • Rehydrate the chat UI with existing messages pulled from the database when loading a past conversation
    • Keep your sidebar list of chats updated using route revalidation, so it always reflects the latest state

    By the end of this workshop, you’ll have a end-to-end persistent chat experience—streaming, saving, routing, and reloading conversations seamlessly. More importantly, you’ll know how to build chat apps that feel real and resilient, not just impressive prototypes.