Replying to Avatar PayPerQ

There's been some buzz in the last two days around LLM API's runnning pay-per-query via lightning payments.

As the creator of an AI service that prioritizes lightning, I wanted to share my experience and also learn a bit from the audience on this matter.

The ultimate dream we all have in the LN community is for each and every query (inference) to be paid for with the requisite amount of satoshis. That way, the user never has to keep a balance with the service and suffer from the host of corresponding inconveniences that arise from that.

When I originally built PPQ, I tried to implement exactly this feature. But when I actually got to doing this, I realized it was pretty hard:

First, generative AI queries are unpredictable in their cost. When a user sends a request, the cost of that request is generally not known until the output has finished streaming.

Second, even if one decided on some sort of fixed pricing per query, the latency to finish a lightning payment costs precious milliseconds and reduces the snappiness of the end product. I don't want to have a user wait an additional 1 second each time for the payment to clear before getting their answer.

To address this, my best idea was to charge an "extra amount" on the user's first query. That way, my service would store a de facto extra balance on behalf of the user. When the user submits their subsequent queries, the system could draw down on this "micro balance" instantly so that it didn't need to wait for the subsequent payment to clear. This micro balance would also serve to mitigate any issues where the user's output was higher than expected. So each subsequent query would always be drawing down on that micro balance and then the users realtime payments are not paying for the query, they are rathing paying to top up that micro balance over and over again.

However, even this method has some weaknesses to it. How much extra money should that first query be? Theoretically the micro balance needs to be as large as the largest possible cost that a query could be. If it wasn't that size, the service makes itself vulnerable to an attack where the users consistently write queries that exceed the amount of money in their microbalances. But the maximum cost of a gen AI query can actually be pretty large nowadays, esp with certain models. So the user's first query would always have a weird "sticker shock" attached to it where they are paying $1-2 for their first query. It creates confusion.

Aside from these problems, the other big problem is that the lightning consumer ecosystem of wallets and exchanges largely do not yet support streaming payments. The only one that does to my knowledge is @getAlby with their "budgeted payments" function in their browser extension.

So even if you were to build a service that could theoretically accept payments on a per query basis, the rest of the consumer facing ecosystem is not yet equipped to actually stream these payments.

In the end, I just adopted a boring old "top up your account" schema where users can come to the website and deposit chunks of money at a time and then draw down upon that balance slowly over time. While boring, it works just fine for now.

I woud like to hear from the community on this issue. Am I missing something? Is there a better way to tackle this? Maybe ecash has a cool solution to this?

nostr:npub12rv5lskctqxxs2c8rf2zlzc7xx3qpvzs3w4etgemauy9thegr43sf485vg nostr:npub1sg6plzptd64u62a878hep2kev88swjh3tw00gjsfl8f237lmu63q0uf63m nostr:npub130mznv74rxs032peqym6g3wqavh472623mt3z5w73xq9r6qqdufs7ql29s

I think the best solution to this, given the requirements you outlined and the need to avoid wasting time on payment processing, is to use Cashu to build a 'trust' relationship based on certain terms, such as a predefined mint for payments. This way, consumers and providers can agree on a mint, and only payments with tokens from that mint will be accepted. This removes the burden of finalising payments, and tokens from that mint can be streamed, meaning those payments could be as fast as reducing the price from a local balance. This only works if a trust relationship is established between the parties: 'consumer -> mint <- provider'. If this trust relationship doesn't exist, you have to redeem Cashu tokens for every payment to reduce counterparty risk.

Another approach would be for you to run your own mint with a custom denomination (or just sats), where customers could buy tokens by minting sats. This approach has some interesting benefits, such as improving the privacy of your users, as the tokens act as both payment and verification. This means that you wouldn't need API keys and could act as a blinded custodian.

Reply to this note

Please Login to reply.

Discussion

If we have to agree on one mint, which is also custodial, what is the actual difference?

I use PPQ by keeping a browser bookmark with my access token and it just works.

How does having cashu tokens improve that user experience?

Cashu is interopperable. The key for your account on ppq is more difficult from a UX perspective.

No, it's simpler from a UX perspective

As I read more of the thread, I realized I had no idea what I was talking about.🤣

Portability and anonymity I think are the most obvious improvements

+1 for anonymity as queries don't need to be linked to an account.

Accounts are trivial to create so you can keep rotating them as often as you want.

Not as fine grained as once per request, but the advantage is I don't have to deal with change.

How do you deal with change in the case of cashu?

If you use smaller denominations, how much do you send if you don't know what the request will end up costing?

nostr:npub16g4umvwj2pduqc8kt2rv6heq2vhvtulyrsr2a20d4suldwnkl4hquekv4h discussed the challenges of change. In SEC-04, nostr:npub1hw6amg8p24ne08c9gdq8hhpqx0t0pwanpae9z25crn7m9uy7yarse465gr and I worked on running CI jobs as DVMs but paid with cashu and returning change. The user (or agent) just pays as much as they want, the more they pay the more the timeout is and the more change they potentially get back. We got an alpha version working with testnuts.

That's pretty cool. And great to hear that you guys figured it out.

If nostr:npub16g4umvwj2pduqc8kt2rv6heq2vhvtulyrsr2a20d4suldwnkl4hquekv4h went for this, how would we configure Roocode for example to work with cashu tokens?

This appears like the biggest problem the Open AI API standard supported by all the tools doesn't include support. I've not used routstr, etc to see how they work but I assume the user would need to run a local proxy to inject the tokens and collect the change.

Would this be a big deal? I'm not sure. The service could run their own custodial proxy to onboard new users with the account based experience nostr:npub16g4umvwj2pduqc8kt2rv6heq2vhvtulyrsr2a20d4suldwnkl4hquekv4h do today.

This mint, would the service provider run it? If so, I wonder if any money transmission laws would come into effect?

Depends, you can externalize that and use a third party mint. There are some money transmission laws about keeping a custodial balance? I would say it's the same. Instead if you run you custom denomination mint these tokens are not money itself, just utility tokens

There are laws around allowing withdrawals. If a service allows withdrawals, then they generally are considered a wallet and have to respect MSB laws.

But yea if you just have them as non-withdrawable credits then it might work. But at that point why not just do a simple top up?

The one advantage I'm aware of is the blinded custodian thing so thats +1 for ecash tokens.

You can run a mint for yourself for only your application with exactly your requirements (limit withdrawals etc)! Hit me up if you need any information, happy to help.

A third party mint would introduce financial risk for the operator which was zero before

Before what? LN custodial you mean?

By before I meant right now, status quo