I've implemented ngx_l402, an Nginx module that enables pay-per-request authentication using the L402 protocol. It allows API providers to monetize their endpoints via Bitcoin and the Lightning Network.
Why ngx_l402?
πΉ Monetize APIs with Bitcoin payments
πΉ Seamless Lightning authentication using L402
πΉ Supports generating invoices via Lightning Network Daemon (LND), Lightning URL (LNURL), and Nostr Wallet Connect (NWC)
πΉ Lightweight & efficient for Nginx users
Check it out:
π GitHub: https://github.com/DhananjayPurohit/ngx_l402
Would love to hear feedback and thoughts! πβ‘
Interesting, but the readme is shy on details. Does it charge per call or per time? Both REST and WS? Suggested use cases?
Thanks for pointing that out! I'll add more details to the README.
It charges per unique call. You'll need to implement a database to invalidate macaroons after each use or based on time.
Currently, it supports REST APIs only; WebSocket (WS) support is not yet implemented.
Real-world use cases can be:
AI & LLM APIs β Charge per request for AI model inferences, ensuring pay-per-use monetization.
Weather & Financial APIs β Monetize access to premium weather forecasts, stock prices, or crypto market data.
Self-hosted SaaS Tools β Implement per-request billing for services like file conversion, image processing, or data enrichment.
Decentralized VPNs & Proxies β Charge users for bandwidth consumption on privacy-preserving networks.
Nice works. Has @fewsats seen this?
Iβve posted it on X as well. They have an uncanny ability to detect anything brewing around L402βit's like they can sense every innovation in the space! Huge respect for @fewsats and their efforts in making L402 a massive success. π
Ofc we have seen it.
Dhananjay thinks that we have an alert for L402 stuff but in reality we are just big fans of the things he builds so when he pushes something we notice :D
I like it more as an nginx module than as a full proxy like aperture. If someone is looking for things to build this proxy + a storage service is a good project to start with.
That's really awesome to hear! I appreciate the support and the keen eye on my work. π
Great work! Will check it out.
Thanks! Let me know if you have any suggestions or feature requests.
Will do. I have already shared your repo with our dev at Predyx, they are super excited about what you built. We will start exploring it in depth in a month or so due to other priorities.
Question: Is there a way we can specify a separate invoice/sats amount for every unique API calls. For example we have a "buy share" API
/api/predictions/buy, each unique API calls would require different sats amount to be paid. The sats amount/invoice can be passed in the http header.Thanks! For now, I've configured the amount field as an environment variable, but I plan to make it configurable per API directly from nginx.conf. Alternatively, I might explore a way to make the amount dynamic, similar to how Aperture handles it.
If you can make it configurable per API using redis/memcache as source of invoice amt, that would be awesome.
Thank you, thatβs a great suggestion, especially for handling dynamic pricing. Iβve created an issue for it and look forward to working on it.
https://github.com/DhananjayPurohit/ngx_l402/issues/7
π