L402 is a protocol for machine-to-machine payments. It allows agents to go out and purchase resources or access tokens to APIs online. If this sounds familiar, you might have heard of it before or of other similar protocols such as X402 or MPP (the Machine Payments Protocol). But in this post, we're talking about L402.
A Quick History Lesson
The HTTP error code 402, "Payment Required," was originally created back in the mid-90s and held for future use. Then, years later in 2020, Lightning Labs created the L402 protocol. This was originally called LSAT, or Lightning Service Authentication Token, and this protocol made use of this long-dormant HTTP error code.
Personally, I think how this works is quite beautiful. And while L402 is token-agnostic, macaroons are recommended and I personally find macaroons to be quite elegant.
If you’d like to be convinced that macaroons are quite elegant, check out this post!
How It Works
I'd like to describe for you the process of how this works, and I'd like you to note the lack of intermediaries and how quick and simple this process is. There's an agent, there's a service, and there's Bitcoin's Lightning Network—and nothing else.
Here's what happens:
A bot shows up to an API and pings an endpoint. It could be an API or any kind of service. It pings an endpoint, and that service responds with the HTTP 402 error code and says, "Hey, you gotta pay for that endpoint!" In this process the service also hands over a bearer token In this case, a macaroon, and with it, a Lightning invoice to be paid.
That agent then goes out and uses Bitcoin's Lightning Network to pay the invoice, and it gets back a preimage, which functions like a receipt of payment.
That agent then takes that macaroon and pairs it together with the preimage to create an L402. It returns to that API endpoint, hands over its L402, and voilà, it is granted access to that endpoint.
This is of course a high level summary and there are many more details. You can find them all here.


Top comments (0)