Skip to content
New Project

Liveblocks Multiplayer AI Chat

A real-time multiplayer chat powered by Liveblocks.

DeployView Demo

Realtime AI chat with AI Elements

This example shows how to build a realtime, multiplayer AI chat with Liveblocks Feeds, Next.js, and AI Elements.

Each chat is a feed inside a Liveblocks room, so messages sync instantly to everyone connected, complete with shared presence (avatar stack and a live "AI is thinking…" status). The AI reply is generated on the server and streamed back into the feed with @liveblocks/node (createFeedMessage + updateFeedMessage), then rendered live for all users through the useFeedMessages hook — including reasoning, chain of thought, tool calls, sources, and token usage via AI Elements.

Getting started

Run the following command to try this example locally:

npx create-liveblocks-app@latest --example nextjs-ai-elements-realtime --api-key

This will download the example and ask permission to open your browser, enabling you to automatically get your API key from your liveblocks.io account.

Manual setup

Read more

Alternatively, you can set up your project manually:

  • Install all dependencies with npm install
  • Create an account on liveblocks.io
  • Copy your secret key from the dashboard
  • Create an .env.local file and add your secret key as the LIVEBLOCKS_SECRET_KEY environment variable
  • (Optional) Add an AI_GATEWAY_API_KEY from the Vercel AI Gateway to get real model responses. Without it, the example uses a built-in mock assistant so it still runs end to end.
  • Run npm run dev and go to http://localhost:3000

To see the realtime sync, open the page in two browser tabs and send a message from one — it appears instantly in both, along with the AI's reply.

Deploy on Vercel

Read more

To both deploy on Vercel, and run the example locally, use the following command:

npx create-liveblocks-app@latest --example nextjs-ai-elements-realtime --vercel

This will download the example and ask permission to open your browser, enabling you to deploy to Vercel.

Develop on CodeSandbox

Read more

After forking this example on CodeSandbox, create the LIVEBLOCKS_SECRET_KEY environment variable as a secret.

GitHub
Ownerliveblocks
Repositoryliveblocks
Use Cases
AI
Realtime Apps
Stack
Next.js
Tailwind
Database
Liveblocks

Related Templates

eve Chat Template

A persisted Next.js chat template for eve, built with shadcn/ui, Tailwind CSS, Streamdown, Better Auth, Drizzle, and Neon.
eve Chat Template thumbnail

Next.js Boilerplate

Get started with Next.js and React in seconds.
Next.js Boilerplate thumbnail

Image Gallery Starter

An image gallery built on Next.js and Vercel Blob.
Image Gallery Starter thumbnail
DeployView Demo