Skip to main content
ForgeMeshPay-per-Crawl for Vercel · v0.1.0 · free, open source

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

middleware.js at the project rootmiddleware.js
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).*)"] };
vercel.json for a plain static foldervercel.json
{ "outputDirectory": "public" }

Turn it on

  1. 1Add a package.json with the dependency if your project is pure static HTML, then install.
  2. 2Add middleware.js next to package.json. A static project also needs vercel.json pointing outputDirectory at your HTML folder.
  3. 3In the Vercel project settings add PAY_TO and PRICE_USD, then deploy. Env vars apply from the next deployment.
  4. 4Test on the production alias (your-project.vercel.app): curl -i -A GPTBot https://your-project.vercel.app/ returns 402.
  5. 5Set MODE=gate and redeploy to start charging.

Settings

PAY_TOYour 0x wallet on Base. Required to charge.
PRICE_USDPrice per page fetch in USDC. Default 0.01, minimum 0.005.
MODEmonitor (default) logs what bots would have paid; gate answers 402.
FACILITATOR_URLAny x402 facilitator that settles on Base. Default PayAI, no API key.
CLASS_POLICYJSON per class: search, social, monitor, seo, ai, automation, bot → free, paid or block.
BOT_OVERRIDESJSON per crawler name, wins over the class: {"GPTBot":"paid","Bytespider":"block"}.
ALLOW_PATHSComma list of path prefixes that are never gated.
TRUST_HEADERHeader carrying the real client IP behind your proxy. Right-most entry is used.
MPP_SECRETLong random string signing MPP challenges. Set it so challenges survive restarts.
PRO_KEYOptional 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:

Other stacks

WordPressNext.jsCloudflare WorkersNodenginxPythonGoPHP