Guide · Developer
How to Add a Video Call to a Next.js App
Add a video call to a Next.js App Router app with @voltkit-rtc/react: a token route handler, a client call page in a server page, speaking rings, token refresh.
- Author
- VoltKit
- Published
- Reading time
- 8 min read
A video call in a Next.js app has three parts: a route handler that mints a token with your API secret, a server page that renders the call, and a client component that joins the room with the hooks of @voltkit-rtc/react, the React SDK of VoltKit RTC. The service runs the media servers and the relays, so there is no WebRTC server to deploy beside your Next.js app. This guide puts the three parts in the right places of the App Router, adds speaking rings, token refresh and a credit notice, and works out what a call costs.
It assumes the App Router and a Next.js version that awaits params. How to add video calling to a React app walks through the call page itself line by line; this guide is about the Next.js parts around it.
Before you start
You need a VoltKit account and an RTC project; the quickstart creates both and gives you the API base URL and secret. A new project starts with every media option off. Open the project's Settings tab, find Media and quality, and switch on video, which includes HD voice. Until you do, people can join the room but nobody can publish, and the SDK refuses the camera with the code media-disabled.
The SDK needs React and react-dom 18 or 19. Browsers offer the camera only on HTTPS or localhost, which next dev gives you; a preview deployment needs HTTPS too.
Every account gets 10,000 free participant-minutes every month, shared by all your projects, at any quality. They are spent before anything paid, so the calls you make while you build cost nothing until they are used up. The rules are in what the free minutes cover.
Step 1: install the SDK
npm install @voltkit-rtc/react @voltkit-rtc/client
The client goes beside the hooks, so your app holds one copy. Put the API base URL and the secret in .env.local as VOLTKIT_RTC_URL and VOLTKIT_RTC_SECRET, without the NEXT_PUBLIC_ prefix: they are read on the server only.
Step 2: the token route handler
The browser never holds your API secret. A route handler under app/api checks who the user is with your own session, decides the room and the role, and asks VoltKit for a short-lived token with the Node.js server SDK:
// app/api/calls/[callId]/token/route.ts: runs on your server only
import { StreamClient } from "@voltkit-rtc/server";
import { currentUser, findCall } from "@/lib/calls"; // your own auth and data
const rtc = new StreamClient({
baseUrl: process.env.VOLTKIT_RTC_URL!,
apiKey: process.env.VOLTKIT_RTC_SECRET!, // never sent to a browser
});
export async function POST(request: Request, { params }: { params: Promise<{ callId: string }> }) {
const user = await currentUser(request);
if (!user) return Response.json({ error: "sign in first" }, { status: 401 });
const { callId } = await params;
const call = await findCall(callId);
if (!call || ![call.callerId, call.calleeId].includes(user.id)) {
return Response.json({ error: "not found" }, { status: 404 });
}
await rtc.ensureRoom({ roomId: call.id, hostIdentity: call.callerId });
const role = user.id === call.callerId ? "host" : "cohost";
const { token, wsUrl } = await rtc.createToken({ roomId: call.id, identity: user.id, role });
return Response.json({ token, wsUrl }, { headers: { "Cache-Control": "no-store" } });
}
Three things matter here. params is a promise in current Next.js, so it is awaited. The reply carries Cache-Control: no-store, so no cache in front of your app keeps a token. And the handler is a POST, so a crawler or a prefetch never mints one by accident. The same endpoint in Python, Go, PHP and Spring Boot is in build a token server.
Step 3: a server page and a client call component
The page stays a server component. It reads the route params and renders the call component with the call id:
// app/calls/[callId]/page.tsx
import { CallPage } from "./call-page";
export default async function Page({ params }: { params: Promise<{ callId: string }> }) {
const { callId } = await params;
return <CallPage callId={callId} />;
}
CallPage is a client component, with "use client" at the top. It fetches the token from the route handler on a click, then renders VoltkitProvider with wsUrl and token; everything below the provider uses the hooks: useRoom for the state and the role, useLocalMedia to publish the camera and microphone, useRemoteTracks for everyone's video and sound, and VideoTrack and AudioTrack to draw them. The complete component, with join, mute, camera off and leave, is a call page in the React SDK docs; copy it as it is into call-page.tsx. Two rules keep it working in Next.js: never make a StreamClient during render (the provider makes it in an effect), and when a session ends, mount a new provider with a new key and a fresh token, because a closed session stays closed.
Step 4: tiles with speaking rings
A tile per person is the usual layout. useIsSpeaking lights a ring while that person talks, and useStreamFallback says when their video is held back for your connection, so the tile can say why it looks soft:
function Tile({ identity }: { identity: string }) {
const [camera] = useRemoteTracks({ identity, source: "camera" });
const speaking = useIsSpeaking(identity);
const heldBack = useStreamFallback(camera?.producerId);
return (
<figure className={speaking ? "tile speaking" : "tile"}>
{camera && <VideoTrack track={camera.track} producerId={camera.producerId} />}
<figcaption>
{identity}
{heldBack && " · poor connection"}
</figcaption>
</figure>
);
}
producerId on a remote VideoTrack turns on adaptive streaming: the video arrives at the size the tile is shown and pauses while the tile is off screen, which is what keeps a grid of eight people smooth on a laptop.
Step 5: keep the call alive
Tokens are short-lived, and the service refreshes them during a session. When nobody has refreshed one and it is about to expire, the client raises tokenExpiring; a small component inside the provider asks your route handler for a new one:
// Inside the provider, beside <Call />:
// <RefreshToken callId={callId} onToken={(token) => setCredentials((c) => (c ? { ...c, token } : c))} />
function RefreshToken({ callId, onToken }: { callId: string; onToken: (token: string) => void }) {
useVoltkitEvent("tokenExpiring", async () => {
const res = await fetch(`/api/calls/${encodeURIComponent(callId)}/token`, { method: "POST" });
if (res.ok) onToken((await res.json()).token);
});
return null;
}
The SDK reconnects by itself when a network drops. Show that it is working rather than a dead screen:
function ConnectionStatus() {
const state = useConnectionState();
const network = useNetworkQuality();
if (state === "reconnecting") return <p role="status">Reconnecting…</p>;
if (network?.level === "poor" || network?.level === "bad") return <p role="status">Your connection is unstable.</p>;
return null;
}
And when the account behind the project is running low, the room is told about a minute before it ends, so the host can recharge in time:
function CreditBanner() {
const { active, remainingSeconds } = useWalletLow();
if (!active) return null;
return <p role="alert">Call credit runs out in about {remainingSeconds} s.</p>;
}
Step 6: deploy
Set VOLTKIT_RTC_URL and VOLTKIT_RTC_SECRET on your host as server-side variables. next build needs neither: tokens are minted at request time, not at build time, so a build with no access to the API still succeeds. Serve the app over HTTPS, which every common host does by default, and the camera works on the first visit.
Test with two people
Open the page in two browsers signed in as two different users. The same identity joining twice replaces its first session, which then ends with the message for replaced. Allow the camera on both sides, start it, and try mute, camera off, leaving and rejoining. Turn Wi-Fi off for a moment: the status line shows "Reconnecting…" and the page comes back without unmounting. If you test from two devices in one room, put one on headphones, or each picks up the other's speakers and you hear echo; see Echo.
What a call costs
Each connected participant is billed per second, at the rate of the media they use. Someone who receives video pays the video rate, even with their own camera off:
2 people × 30 minutes = 60 participant-minutes
60 participant-minutes × 99 ÷ 1,000 = 5.94 credits, ₹5.94 (≈ $0.06) at today's rate
Full HD Video + HD Audio: 99 credits per 1,000 participant-minutes. Billed per second, so a 7½-minute call costs 7½ minutes.
Prices are in Indian rupees; dollar figures are approximate, at ₹95 per US dollar on 24 October 2026, for orientation only. You are billed in rupees.
5 people × 45 minutes = 225 participant-minutes
225 participant-minutes × 99 ÷ 1,000 = 22.275 credits, ≈ ₹22.27 (≈ $0.23) at today's rate
Full HD Video + HD Audio: 99 credits per 1,000 participant-minutes. Billed per second, so a 7½-minute call costs 7½ minutes.
The free minutes of the month are spent first and reset on the 1st (UTC); used up, the rest is billed from your wallet or plan at the same rates.
Tokens, API calls and chat messages cost nothing. What is a participant-minute? explains the unit, the pricing page has every rate, and the calculator works out your own session.
Where to go next
- React SDK: every hook and component, the errors you will meet and the Next.js notes.
- Add live chat to a web app: chat beside the call, on the same connection.
- Screen sharing and Video quality: the rest of a call.
- How to choose a video calling SDK: a checklist, if you are still comparing.
While you develop, the JWT Decoder shows a test token's expiry on your own device and never sends it anywhere:
Inspect a test token with theJWT DecoderUse test tokens only: a token is a credential for a room, and production tokens belong only to the app that asked for them.
Frequently asked questions
Does the VoltKit React SDK work with the Next.js App Router?
Yes. Every module of @voltkit-rtc/react starts with "use client", so a server component may import it, and the components that call its hooks are client components. The provider makes its client in an effect, so nothing runs during server rendering and the page hydrates without a mismatch.
Where does the API secret go in a Next.js app?
In a server-only environment variable, read by a route handler under app/api. Never prefix it with NEXT_PUBLIC_, which would ship it to the browser. The route handler calls VoltKit with the secret and returns only a short-lived token and the wsUrl to the page.
Can the call page be a server component?
The page itself can be: it reads the route params and renders a client component with the call id. The call component, which uses the hooks, is a client component. That split keeps the SDK out of server rendering and still gives you a normal Next.js route.
Why does the camera not start on my preview deployment?
Browsers offer the camera and microphone only on HTTPS or localhost, so a preview served over plain HTTP cannot open them. Also check that video is switched on under the project's Settings, Media and quality: a new project starts with every media option off and the SDK then refuses with media-disabled.
Does it cost anything to test the call while I build?
VoltKit gives every account a monthly allowance of free participant-minutes, spent before anything paid, at any quality, so building and testing a call usually costs nothing. The live number is on the free minutes page. After them, each participant is billed per second at the rate of the media they use.