@forgemeshlabs/pay-per-crawl-vercel
v0.1.0
Published
Vercel Edge Middleware that answers AI crawlers with x402 / MPP pay-per-crawl, for any Vercel project (static sites, Astro, SvelteKit, Vite, Nuxt, Remix...). Owner keeps 100%, no account, no custody.
Maintainers
Readme
@forgemeshlabs/pay-per-crawl-vercel
Vercel Edge Middleware that charges AI crawlers per page with x402 and MPP. Works in front of anything Vercel serves: a static site, Astro, SvelteKit, Vite, Nuxt, Remix, Hugo, Docusaurus. (Next.js projects: use @forgemeshlabs/pay-per-crawl-next, same engine.) Only Web APIs, DNS-over-HTTPS for search-engine verification. You keep 100%: no account, no custody.
npm install @forgemeshlabs/pay-per-crawl-vercelmiddleware.js at the project root (next to package.json):
import { createPayPerCrawl } from "@forgemeshlabs/pay-per-crawl-vercel";
const ppc = createPayPerCrawl({ siteName: "My Site" }); // PAY_TO, PRICE_USD, MODE ... come from env; options win
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).*)"] };Then in the Vercel project settings → Environment Variables: PAY_TO = your wallet (0x address on Base), PRICE_USD = 0.01, MODE = monitor. Deploy. Watch the function logs for what bots would have paid, then set MODE=gate and redeploy to charge.
Environment (all optional if passed as options): PAY_TO, PRICE_USD (min 0.005), MODE (monitor default, gate to charge), FACILITATOR_URL, CLASS_POLICY, BOT_OVERRIDES, ALLOW_PATHS, TRUST_HEADER, MPP_SECRET, PRO_KEY.
The middleware also serves /.well-known/x402.json, /llms.txt and /agents.txt. Prefer Edge Functions for those? export default ppc.handlers.x402Json; in api/x402.js with a rewrite, or just let the middleware do it.
Notes
- A pure static project needs a
package.jsonfor the dependency;vercel.jsonwith"outputDirectory": "public"(or your folder) keeps the HTML where it was. Seeexamples/vercel-static. TRUST_HEADERdefaults tox-forwarded-forand the right-most entry is used, which is the one Vercel appended. A client cannot forge a search-engine IP by prepending it.- Replay lock and rDNS cache are per-isolate memory; pass
store(any{get, put, delete}, e.g. Vercel KV / Upstash) for a shared one. On serverless this is best effort; the on-chain nonce is the hard guard. /_vercel/*, static assets and non-GET/HEAD requests pass free. Bugs and bad config fail open: the site never goes down because of the gate.- Edge Middleware runs on every matched request, including bots that never pay. Vercel's Edge Middleware invocations are metered on paid plans; the free Hobby plan has a generous allowance.
How money flows
Crawler signs a USDC authorization; the middleware has the facilitator (PayAI by default) verify and settle, and serves the page only on a settlement transaction hash. USDC lands in PAY_TO.
MIT.
