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

Charge AI crawlers in Express, Fastify, Hono or Koa

One adapter package for the four common Node servers. Mount it before your routes and every page is gated the same way.

Works with: Express, Fastify, Hono (Node, Bun, Deno, Workers), Koa

Install

npm install @forgemeshlabs/pay-per-crawl-node

Add the gate

Express
import { payPerCrawl } from "@forgemeshlabs/pay-per-crawl-node/express";
app.use(payPerCrawl({ payTo: "0xYourWallet", mode: "monitor" })); // before your routes
Fastify
import { payPerCrawl } from "@forgemeshlabs/pay-per-crawl-node/fastify";
await app.register(payPerCrawl, { payTo: "0xYourWallet", mode: "gate" });
Hono
import { payPerCrawl } from "@forgemeshlabs/pay-per-crawl-node/hono";
app.use("*", payPerCrawl({ payTo: "0xYourWallet" }));
Koa
import { payPerCrawl } from "@forgemeshlabs/pay-per-crawl-node/koa";
app.use(payPerCrawl({ payTo: "0xYourWallet" }));

Turn it on

  1. 1Install the package and mount the adapter for your framework before your routes.
  2. 2Pass payTo and priceUsd as options, or set PAY_TO and PRICE_USD in the environment.
  3. 3Run in monitor mode first and read the per-request events, then set mode: "gate".

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

  • Express, Fastify and Koa verify search engines with Node DNS. Hono uses DNS-over-HTTPS so it also runs on edge runtimes.
  • Set trustHeader only to a header your own proxy overwrites or appends, such as x-forwarded-for behind nginx. Without it the socket address is used.
  • Replay lock is in memory per process. Pass a store to share it across instances.
  • 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:

  • Same core as the Next.js edition; mainnet hashes on that guide

Other stacks

WordPressNext.jsVercelCloudflare WorkersnginxPythonGoPHP