Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
A realtime, multiplayer AI chat example built with Liveblocks Feeds, Next.js, and AI Elements, with presence and server-streamed AI replies.
Realtime AI chat with AI Elements is a Liveblocks starter example that combines Liveblocks Feeds, Next.js, and the AI Elements library from ai-sdk.dev to build a multiplayer AI chat where messages and AI replies sync instantly across clients.
Realtime AI chat with AI Elements is a starter example from Liveblocks that runs on Next.js and uses Liveblocks Feeds for the chat backend. Each chat is a feed inside a Liveblocks room, and the app takes a user message as input and produces a server-generated AI reply that is streamed back into the same feed with @liveblocks/node, using createFeedMessage and updateFeedMessage. It is maintained by Liveblocks and is part of the liveblocks/liveblocks GitHub repository, with a live preview, CodeSandbox fork, and Vercel deployment flow documented on the page.
@liveblocks/node, then rendered live through the useFeedMessages hook.npx create-liveblocks-app@latest --example nextjs-ai-elements-realtime --api-key downloads the example and can open your browser to fetch an API key.AI_GATEWAY_API_KEY from Vercel AI Gateway for real model responses; without it, a built-in mock assistant keeps the example running end to end.--vercel flag, and a CodeSandbox template is available for browser-based development.@liveblocks/node API.--vercel flag, or fork the CodeSandbox and add LIVEBLOCKS_SECRET_KEY as a secret.npx create-liveblocks-app@latest --example nextjs-ai-elements-realtime --api-key; the command downloads the app and can open your browser to automatically get an API key from your liveblocks.io account.LIVEBLOCKS_SECRET_KEY in .env.local, and optionally set AI_GATEWAY_API_KEY from Vercel AI Gateway.npm run dev and open http://localhost:3000 in two browser tabs. Sending a message in one tab instantly updates the other, complete with presence and the streamed AI reply.No. Without AI_GATEWAY_API_KEY the example uses a built-in mock assistant, so the full flow runs end to end. Adding a key from Vercel AI Gateway switches it to real model responses.
AI Elements is a UI library from ai-sdk.dev that renders AI-generated data. In this example it displays the assistant's reasoning, chain of thought, tool calls, sources, and token usage alongside the chat feed.
Yes. Run npx create-liveblocks-app@latest --example nextjs-ai-elements-realtime --vercel to download the example and set up a Vercel deployment. The command asks permission to open your browser to authorize the deployment.
Run npm run dev and open http://localhost:3000 in two browser tabs. Send a message from one tab and it appears instantly in the other, along with the avatar stack and the live "AI is thinking…" status.
