Charge AI crawlers on any site hosted on Vercel
One Edge Middleware file in front of whatever Vercel serves: a static site, Astro, SvelteKit, Vite, Nuxt, Remix, Hugo, Docusaurus. No server needed. Next.js projects use the Next.js guide instead.
Works with: Vercel Edge Middleware, any framework except Next.js
Install
npm install @forgemeshlabs/pay-per-crawl-vercel
Add the gate
import { createPayPerCrawl } from "@forgemeshlabs/pay-per-crawl-vercel";
const ppc = createPayPerCrawl({ siteName: "My Site" });
export default ppc.middleware;
// Vercel needs config as a literal in this file; it cannot be re-exported.
export const config = { matcher: ["/((?!_vercel|favicon.ico).*)"] };{ "outputDirectory": "public" }Turn it on
- 1Add a package.json with the dependency if your project is pure static HTML, then install.
- 2Add middleware.js next to package.json. A static project also needs vercel.json pointing outputDirectory at your HTML folder.
- 3In the Vercel project settings add PAY_TO and PRICE_USD, then deploy. Env vars apply from the next deployment.
- 4Test on the production alias (your-project.vercel.app): curl -i -A GPTBot https://your-project.vercel.app/ returns 402.
- 5Set MODE=gate and redeploy to start charging.
Settings
| PAY_TO | Your 0x wallet on Base. Required to charge. |
|---|---|
| PRICE_USD | Price per page fetch in USDC. Default 0.01, minimum 0.005. |
| MODE | monitor (default) logs what bots would have paid; gate answers 402. |
| FACILITATOR_URL | Any x402 facilitator that settles on Base. Default PayAI, no API key. |
| CLASS_POLICY | JSON per class: search, social, monitor, seo, ai, automation, bot → free, paid or block. |
| BOT_OVERRIDES | JSON per crawler name, wins over the class: {"GPTBot":"paid","Bytespider":"block"}. |
| ALLOW_PATHS | Comma list of path prefixes that are never gated. |
| TRUST_HEADER | Header carrying the real client IP behind your proxy. Right-most entry is used. |
| MPP_SECRET | Long random string signing MPP challenges. Set it so challenges survive restarts. |
| PRO_KEY | Optional Pay-per-Crawl Pro license for the hosted dashboard. |
Things to know
- Per-deployment URLs (your-project-abc123-team.vercel.app) sit behind Vercel Authentication by default and answer 302 to a login page. Test the production alias or a custom domain.
- Vercel appends the client IP to X-Forwarded-For; the gate reads the right-most entry, so a client cannot prepend a search-engine IP.
- Edge Middleware runs on every matched request, paying or not. Hobby has a generous allowance; paid plans meter invocations.
- Replay lock and reverse-DNS cache are per-isolate memory. Pass a store such as Vercel KV for a shared one.
- Behind Cloudflare, set AI Crawl Control and any "Block AI bots" rule to Allow for the crawlers you want to charge. A crawler blocked at the edge never reaches the gate and never sees the 402.
- Humans never see a 402. Search engines are verified by reverse DNS; a request that only claims to be Googlebot is charged.
- Start in monitor mode. It logs every bot with what it would have paid and never blocks. Switch to gate when the numbers make sense.
Proof it settles
Real settlements on Base mainnet through the PayAI facilitator, $0.01 each, October 2026:
- x402 v2 through a static site on Vercel (ppc-vercel-demo.vercel.app)0xcc37097ef97b74f5ff0361cc98344bffce8fbba48bfdf3354c9094b1eec93766