HTTP 402 as a working payment channel
Wrap an existing API so that requests pay you bitcoin.
The anchor for a cluster of 2016 experiments. Flask, plus two1.wallet and
two1.bitserv.flask from 21.co, in about forty lines.
The mechanism is HTTP 402, the status code reserved in the original spec for
“Payment Required” and never used, which 21’s stack made real. A
@payment.required(n) decorator prices a single route in satoshis. An unpaid
request returns 402 with payment terms in the headers. The client pays over a
payment channel, retries with proof, and the server verifies and serves. A
/manifest route publishes manifest.yaml so 21’s crawler could find the
service and list what it did and what it cost.
The idea was good and it is worth being clear about why it did not work. The
caller needed a funded bitcoin wallet and the two1 library installed, so the
addressable market for any of these APIs was other machines already inside 21’s
ecosystem. A payments layer whose participants must all adopt one company’s
client is not a payments layer for the web, it is an intranet.
Micropayments per API request remains a good idea waiting on a client everyone already has, which nine years later is a live question again as agents start making paid calls.