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

Reply to this note

Please Login to reply.

Discussion

ooooo

sweet 🤙

Can ELI5 please kind ser?

Paid API services with ecash so that nobody can track the users. This is fascinating new stuff!

Thanks! #[3]​ you seen this?? 🔥

I really gotta take a look at your work once I have a second to chill.

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

Yes, baby, bring it on

This is the way to fix surveillance capitalism

Do you even sleep at all?! 💥🪄

This is what happens when you replace water with coffee & club mate

NO

Cool.

Is this effectively a way to have pay per API call using cashu? Basically enabling pay per consumption using micro transactions?

Yes, that's the idea!