Charge training crawlers a dollar a day with @profullstack/x402-gateway - #173
Merged
Conversation
robots.txt used to welcome every AI crawler by name, on purpose. A Railway log sample put ClaudeBot at 54% of upstream compute and meta-externalagent at 11%, none of it sending a reader back, so the welcome is now split the way the operators split themselves: retrieval crawlers (OAI-SearchBot, Claude-SearchBot, PerplexityBot, Googlebot, Bingbot) read free; training crawlers (GPTBot, ClaudeBot, CCBot, meta-externalagent, Bytespider, Applebot-Extended) get 402 Payment Required with an x402 offer, or the sales page at /crawl, and a paid pass in x-crawl-pass opens the site for a day. People are never matched. The gateway lives in apps/web/src/lib/crawl-gateway.js and the proxy asks it first; robots.txt is generated from the same lists so the file and the 402 cannot disagree. The structured entry points (/llms.txt, /skill.md, /api/feeds, /opml, /mcp) stay open to everyone via openPaths. Every env variable is read through a non-literal key because Next inlines process.env.NAME at build time and the image is built without the secrets. Until COINPAY_X402_KEY and CRAWL_PAY_TO are set on the web service the training crawlers are answered 402 with an empty offer. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WJaXiqE9BDoNfoJBhfXroC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes, for whom
402 Payment Requiredwith an x402 offer ($1 buys a day, USDC settled by CoinPay), or the HTML sales page at/crawl; robots.txt saysDisallow: /+Allow: /crawlx-crawl-pass/llms.txt,/skill.md,/api/feeds,/opml,/mcp(and/api/mcp),/robots.txtopenPathsContext: a Railway log sample had ClaudeBot at 54% of upstream compute and meta-externalagent at another 11%, none of it sending a reader back. Matching is on the self-declared crawler token, so a browser user agent never sees any of this.
How
apps/web/src/lib/crawl-gateway.jsbuilds the gateway once, from@profullstack/x402-gateway@0.1.0, so the proxy and robots.txt share one set of lists. It readsSITE_URLitself rather than importingsiteUrl()fromlib/db.js, because that module pulls in the libSQL client and the gateway must stay edge-clean. Every variable is read through a non-literal key: Next inlinesprocess.env.NAMEat build time and the Docker image is built without the secrets.apps/web/src/proxy.jsnow asks the gate first (const answer = await gate(request); if (answer) return answer;) and then runs the throttle, the hint repair and the counter as before. A 402 is still recorded in the traffic ledger, as a refusal, so the price can be judged against what it turns away. The matcher is unchanged.apps/web/src/app/robots.txt/route.jsis generated bygateway.robotsTxt({ disallow: ['/login', '/api/'], allow: ['/api/feeds', '/api/mcp'], comments }). The doc comment records the policy change; the entry-point advertisement survives as the comment block at the top of the file. Note the newDisallow: /loginandDisallow: /api/for the welcomed groups (both used to be allowed by the blanketAllow: /).apps/web/test/crawl-gateway.test.js: robots.txt refuses GPTBot and meta-externalagent withDisallow: /, names OAI-SearchBot withAllow: /, keeps the sitemap and the entry-point comments; the gate answers ameta-externalagentrequest to/feeds/anythingwith 402 (empty offer, no key set), lets Chrome, Googlebot and OAI-SearchBot through, leaves the entry points open, and answers/crawlfor everyone.proxy.jscannot be imported under plain Node (next/serverhas no ESM export map), so its ordering is asserted from source the waytest/proxy.test.jsreads the matcher..env.exampledocuments the two variables.Railway: two variables on the web service
COINPAY_X402_KEY= a scoped CoinPay key (cp_live_…, from the business's API Keys tab, withpayments:create; the legacy business key is refused by CoinPay's x402 routes). Also the pass-signing secret.CRAWL_PAY_TO= the EVM address that receives the USDC (Base, Polygon and Ethereum alike).Until both are set, training crawlers get
402with an empty offer and a sales page that says payments are off: nothing is sold, but nothing is given away either.Verified
pnpm -r test: 1,462 tests, 0 failures, 12 workspaces (9 new).pnpm --filter @rssamplifier/web build: compiles, Proxy (Middleware) listed, 31 s.🤖 Generated with Claude Code
https://claude.ai/code/session_01WJaXiqE9BDoNfoJBhfXroC