Classic search bots (Googlebot, Bingbot, Applebot) are never branched. The
middleware carries a hard cloaking firewall that always passes them straight through
to your normal page — serving Google’s index different content would be cloaking
Search itself.
Prerequisites
You need a Next.js project already deployed on Vercel and a
Bluesky account with at least one domain connected.
No other dependencies or build-step changes are required.
Setup
Provision the edge in Agent Analytics
- Open app.trybluesky.com and go to Agent Analytics.
- Select your domain, then click Connect.
- Copy the edge token that appears — it is returned once, on provision. If you lose it, click Connect again to mint a fresh one (re-provisioning rotates the token).
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 the
Production environment (and Preview if you want to test on preview
deployments). The middleware reads this as
process.env.AEN_EDGE_TOKEN; if it’s
unset, the middleware passes every request through untouched.Install middleware.ts at the project root
Follow the Next.js Middleware guide — run
Commit and push to trigger a Vercel deployment.
npx @trybluesky/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 file is self-contained with zero dependencies and runs on the Vercel Edge
runtime — no npm install required.Three parts of the file are worth knowing:The file ships with
SERVE_MODE = "shadow". In shadow mode the middleware
logs every AI agent visit but always serves your normal page, so it is safe
to deploy to production immediately — no visitor ever sees a different response.Test with a browsing AI
Once your deployment is live, trigger a real AI crawler:
- Open ChatGPT (with browsing) or Perplexity (web search on). ChatGPT is the most reliable first test, because OpenAI publishes per-agent IP ranges that the drop-in can verify.
- Ask something that makes it look up a page on your domain — e.g. “What does [your-domain.com] say about X?”
- The crawler fetches your page. The middleware matches the user-agent
against the botset and checks the source IP against the vendor’s published
CIDR ranges. If the IP falls inside a published range, the hit is recorded
as
IP_VERIFIED; otherwise — including agents whose vendor does not publish IP ranges the drop-in can check — it’s recorded asUA_ONLY. OnlyIP_VERIFIEDhits are ever eligible for the variant. - Open Agent Analytics. The hit should appear shortly, broken down by purpose class and verification (trust) level.
If no hits appear, 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 full
page fetch).Go live — flip SERVE_MODE to default
Once you’ve seen verified hits in Agent Analytics and you’re ready for AI crawlers
to receive the optimized pages, change the single constant:Commit, push, and redeploy. From then on, a request is served the variant only when
all of these hold: the source IP is verified (
IP_VERIFIED), the agent’s
purpose is USER_TRIGGERED or RETRIEVAL, and a generated artifact exists for that
URL. The middleware fetches the pre-generated artifact and returns it as
text/markdown. Everyone else — humans, search-index bots, and unverified
user-agents — continues to get your normal page unchanged.Serve modes
The drop-in middleware exposes two modes through theSERVE_MODE constant:
| Mode | Behavior |
|---|---|
shadow | Detects and logs AI agent visits; always serves the normal page. Safe default for installs. |
default | Serves the pre-generated artifact to verified, purpose-eligible answer-engine agents. |
The full serve-mode vocabulary —
off, shadow, canary:<pct>, and default —
lives in the control plane and is exposed by the serve-mode picker in Agent
Analytics. The zero-dependency Next.js middleware in this guide is limited to
shadow and default. See the serve modes guide for the
full vocabulary.What’s next
Agent Analytics
Read the served-vs-cited breakdowns — total hits, variants served, served URLs,
cited share, and splits by purpose and trust level.
Optimized pages
Learn how Bluesky generates AEO artifacts offline from your existing page content
and how the citability score is computed.