Global Feed Post Login
Replying to Avatar calle

X-Cashu – HTTP 402: Payment Required

Sell anonymous API access with Lightning + Cashu. Paid APIs require ecash in the X-Cashu http header.

Incredible anonymity for users: The server does not know which user has accessed which endpoint. The initial Lightning payment for the "top up" can't be linked to the actual API use. This is freaking awesome! 🔥

Screenshot 1:

- Hit a free endpoint without ecash, all good ✅

- Hit a paid endpoint without ecash, get 402 ❌

- Hit a paid endpoint with ecash, all good ✅

Result of some basic performance tests:

- 1000 requests without Cashu: 3.6s

- 1000 requests with Cashu: 8.5s

That's not too bad!

Implementation:

The server-side implementation is a Python FastApi middleware. It is literally plug and play and extremely simple since Cashu is a library you can include.

The client-side implementation is a Cashu wallet that puts ecash into HTTP headers before each request. This is also in Python (using requests lib) but I'll make a minimal Javascript version to demonstrate its use in a web browser.

This is the best thing since Cashu.

https://void.cat/d/5gAc8UwVSMkG5Q64BMZm9K.webp

Avatar
nostrils 2y ago

Where is the performance hit coming from? How did you test it?

Reply to this note

Please Login to reply.

Discussion

No replies yet.