Skip to main content
Bluemoon’s Agent Edge Network (AEN) runs as middleware inside your own Next.js app on Vercel. It recognises AI answer-engine crawlers (ChatGPT, Perplexity, Claude and others) and checks that each one really comes from the AI company it claims to be. By the end of this guide the middleware is live in shadow mode, logging every AI crawler visit to Agent Analytics, and you know the one change that starts serving those crawlers a clean, citation-ready version of each page — without touching your application code or your search rankings.
Classic search bots (Googlebot, Bingbot, Applebot) always receive your normal page. Google’s AI Overviews use the same crawl as Google Search, so serving them anything else would be cloaking Search itself.

Prerequisites

You need a Next.js project already deployed on Vercel and a Bluemoon account with at least one domain connected. No other dependencies or build-step changes are required.

Setup

1

Get your edge token in Agent Analytics

  1. Open app.trybluemoon.com and go to Agent Analytics.
  2. Select your domain, choose Next.js / Vercel, then click Connect edge.
  3. Copy the edge token that appears. It is shown once. If you lose it, open Setup in Agent Analytics and click Regenerate to get a new one (the old one stops working immediately).
The token is scoped to a single site and can be revoked. It is not your account API key, so a leaked edge token can be replaced without touching the rest of your account.
Store the token before leaving the page. If you lose it, you can only get a new one.
2

Add AEN_EDGE_TOKEN to Vercel

In the Vercel dashboard, go to your project → Settings → Environment Variables and add:
Replace the placeholder with the token from Step 1. Enable it for Production (and Preview if you want to test on preview deployments). If the variable is missing or empty, the middleware lets every request through untouched and records nothing.
3

Install the middleware at the project root

Follow the Next.js Middleware guide: run npx @trybluemoon/aen init, or copy the self-contained middleware.ts, and place it at the root of your Next.js project (the same level as package.json).The copy-paste file has zero dependencies and runs on the Vercel Edge runtime. Two parts of it are yours to change:
Commit and push to trigger a Vercel deployment.
The middleware ships in shadow mode. It logs every AI crawler visit but always serves your normal page, so it is safe to deploy to production immediately — no visitor ever sees a different response.
4

Test with a browsing AI

Once your deployment is live, trigger a real AI crawler:
  1. Open ChatGPT (with browsing) or Perplexity (web search on). ChatGPT is the most reliable first test: its visits can be verified.
  2. Ask something that makes it look up a page on your domain — e.g. “What does [your-domain.com] say about X?”
  3. The crawler fetches your page. If Bluemoon can confirm the crawler comes from the AI company it claims, the visit is recorded as Verified (IP_VERIFIED); if it recognises the crawler but cannot confirm it, the visit is recorded as Unverified (UA_ONLY). Only verified visits can ever receive the optimized version.
  4. Open Agent Analytics. The visit should appear shortly under Recent activity, marked Verified or Unverified, and counted under Why they came.
If nothing appears, confirm that AEN_EDGE_TOKEN is set in Vercel, that the deployment containing middleware.ts is the active one, and that the AI tool actually fetched a page (some prompts trigger a web search but not a page visit). See Troubleshooting.
5

Go live — switch the serve mode to default

Once you’ve seen verified visits in Agent Analytics and you’re ready for AI crawlers to receive the optimized pages, switch the serve mode.With the copy-paste file, change the constant:
With the npm package, set AEN_SERVE_MODE=default in your Vercel environment variables.Redeploy. From then on, a crawler receives the optimized version only when all of these hold: it is verified (IP_VERIFIED), its purpose is USER_TRIGGERED or RETRIEVAL, and an optimized version exists for that URL. Everyone else — humans, search bots and unverified crawlers — keeps getting your normal page.

Serve modes

The Next.js middleware supports two modes: See Serve modes for how to roll out safely.
Search bots (Googlebot, Bingbot, Applebot) always receive your normal page, whatever the serve mode.

What’s next

Agent Analytics

AI requests, the crawlers that visit you and why, what each visit received, and how many of the pages served to AI were later cited.

Optimized pages

What AI crawlers receive, and how to check and regenerate each page’s optimized version.