-
Notifications
You must be signed in to change notification settings - Fork 15
LNURL AI API brainstorming
A user wants to hit an AI endpoint, so they hit api.whatever.com/.well-known/lnai and receive the following response:
{
"models": [
{
"model": "gpt3",
"url": "<url to hit to interact with it>",
"per_token_in": 0.0,
"per_token_out": 0.003,
"per_request": 0.0
},
// Add more models and prices as needed
],
"lnurl": "<lnurl for payment>"
}The user initiates the LNURL protocol, and the service replies with the following payerData:
{
// ...standard lnurl payerdata fields.
"auth_token": {"mandatory": true}
}The user can calculate their usage based on the model they plan on using. Doing this in advance is important so the payment system doesn't induce latency. However, it need only be done for a few minutes in advance because lightning is fast and settlement is final.
The user uses LNURL to pay, in advance, for their expected usage. The payment should be enough to cover the future usage before the next payment. An accurate estimation engine, that uses streams of requests and a geomentric mean and standard deviation should be suitable to predict the next 10 minutes of usage with a 99.999% certainty. That gets paid for in advance. A standard engine for this can be built and included with the protocol examples.
Finally, the user makes a POST request to the URL of their choice with a BEARER token from the LNURL service payment, and the SAME api parameters they are used to. Since BEARER tokens are standard in AI, and no major changes have been made to the flow, all that's necessary for the service provider to implement is "inserting the auth_token along with token limits into a db"... something they are already doing today.
The remote ai service responds an error without performing work if its estimated tokens don't match what has been paid on that particular token.
The end-user can request a sweep to a new auth_token at any time by using the following endpoint:
api.whatever.com/.well-known/lnai/sweep?from=old_token&to=new_token
Replace old_token with the current auth_token, and new_token with the desired new auth_token.