Verb
All integrations

Verb for Next.js

Add an AI agent to your Next.js app

Quick answer

Paste Verb's script tag into app/layout.tsx inside <body>, add a route handler at app/api/verb-token/route.ts that signs the logged-in user's id with HMAC-SHA256, and hand that token to the widget. The agent then carries out your users' requests through your app's own API as them, asking before it changes anything. It is integrated in under an hour in most cases.

Rather not do it by hand? Your coding agent can: see Verb for Claude Code or Cursor.

1. Add the script tag

Put it in app/layout.tsx, inside <body> below {children}, once. Your site key is in the dashboard.

HTML
<script src="https://api.askverb.com/v1/verb.js"
        data-verb-site="YOUR_SITE_KEY" defer></script>

If you send a Content-Security-Policy, it is usually in next.config headers() or middleware: add https://api.askverb.com to script-src and connect-src.

2. Mint a token on your server

Verb treats every visitor as anonymous until your server says who they are. Sign the logged-in user's id and a short expiry with the key from your dashboard. Both halves are base64url without padding: standard base64 is the one mistake that fails every token while looking right in a log.

javascript
// app/api/verb-token/route.ts
import { createHmac } from "node:crypto";
import { auth } from "@/lib/auth"; // however you know who is signed in

export async function GET() {
  const session = await auth();
  if (!session?.user) return new Response("Unauthorized", { status: 401 });

  const claims = {
    sub: String(session.user.id),      // your own user id
    exp: Math.floor(Date.now() / 1000) + 900,
  };
  const body = Buffer.from(JSON.stringify(claims)).toString("base64url");
  const sig = createHmac("sha256", process.env.VERB_SIGNING_KEY!)
    .update(body).digest("base64url");

  return Response.json({ token: `${body}.${sig}` });
}

3. Hand it to the widget

In App Router, run this from a client component that mounts once, such as one in your root layout, inside a useEffect.

javascript
const getSessionToken = () =>
  fetch("/api/verb-token", { credentials: "same-origin", cache: "no-store" })
    .then(r => r.json())
    .then(({ token }) => token);

// Sign in now, and let the widget ask again when the token gets old.
window.Verb.configure({ getSessionToken });
getSessionToken().then(token => token && window.Verb.identify(token));

// And wherever your app signs somebody out:
// window.Verb.reset();

The widget asks for a fresh token before the old one expires, and clears the conversation when a different person signs in. The identity docs cover the details.

4. Describe what it may do, then test it

List the actions in a verb.md: each one says whether it reads or writes, and anything that writes asks the user for a yes with the real values first. Every site comes with a test site that only answers on localhost, so you try it against your development data before your users see it. Actions that need your app's own client go through an adapter.

Frequently asked questions

Does it work with the Pages Router?

Yes. Put the script tag in pages/_document.tsx inside <body> below <NextScript />, and the token endpoint in pages/api/verb-token.ts with the same signing code.

Do I need to change my Next.js backend to add Verb?

Only one small endpoint that signs who is logged in. Everything the agent does goes through the API your app already has, as the signed-in user, so your existing routes, permissions and validation stay exactly as they are.

What happens if I skip the token step?

Reading works and every change is refused, because Verb treats every visitor as anonymous until your server says who they are. Users see an honest "you need to sign in" even though they are, which is the sign the token step is missing.

Other stacks

Give your Next.js app its own AI agent

Integrated in under an hour in most cases. Start with a free 30-day pilot, then we price it on what it actually does for your users.