Blockchain-Powered AI: Building a GPT That Pays for APIs with Nano-Transactions
Introduction
In the future, AI will evolve beyond passive economic entities that humans interact with. Instead, AI systems will engage directly with the economy, making autonomous decisions about paying for goods and services. A prominent example of this evolution is AI paying per-use for APIs. This blog post details how we built a custom GPT capable of making nano-payments directly to APIs, enhancing its functionality and autonomy.
Understanding Nano-Payments
Nano-Payments Enabled by Payment Channels on Blockchains
Nano-payments are micro-transactions facilitated by payment channels on blockchain networks. These channels allow for quick, low-cost transactions by aggregating multiple small payments into larger transactions settled on the blockchain.
Benefits and Examples of Nano-Payment Implementations
Nano-payments offer numerous benefits to users. For example, they increase flexibility for the user because they reduce upfront payment commitments (e.g., subscriptions). The knock-on effect of this is that offering a service in exchange for nano-payments can result in higher conversion rates for the entity accepting nano-payments, allowing them to capture more revenue from their users. Indeed, a recent article demonstrated that SaaS providers that adopt usage-based pricing grew 38% faster than those that didn't. Example areas where nano-payments can be effectively utilized include:
APIs: Pay-per-use API access, enabling fine-grained billing.
Content Monetization: Microtransactions for articles, videos, or other digital content.
IoT Devices: Handling micropayments for data exchange between devices.
Building our GPT
In this section, we'll discuss how we gave our custom GPT the ability to make nano-payments.
Create a new GPT
We start at the [explore GPTs](https://chatgpt.com/gpts) section, where we see the "Create" button to create a new GPT.
Once we created a new GPT, we configured it by clicking "Configure". We then gave ours the following instructional message:
When the user first starts communicating with you, you should unconditionally give them the following message:
==
Welcome to XRPL Advisor. I allow you to access paid APIs from Bithomp and XRPL Services using layer-2 XRPL nano-payments. Requests will cost between 0.0002 and 0.0005 XRP.
Ask something like "Tell me about the issuer of this NFT: 000822B03EA060FD1026C04B2D390CC132D07D600DA9B08270A2D1E200000048"
==
After you receive each message from the user, use the action that you have been provided, which references an OpenAPI JSON file for the URL https://run.api.dhali.io
After each message, you should attempt to find actionable insights from the above API. Remember, when requesting the API above, you should always use the Payment-Claim header.
The key to enabling nano-payments for our GPT is the "Actions" section. We clicked "Create new action":
Implementing a JSON Spec Action with Nano-Payments
Overview of the JSON Spec
The JSON spec tells the GPT what the API can do and how to use it. We utilized an Open API JSON specification for a [Dhali](https://dhali.io)-linked API, which can be found here. We copied this into the "Schema" section.
Creating a Nano-Payment
Creating a nano-payment can be done through Dhali using a payment claim. This is currently limited to the XRPL (XRP Ledger). However, this framework could be extended to support any blockchain-based currency in the future. We create a payment-claim by going over to https://pay.dhali.io and following the instructions to get a new payment claim.
Configuring Nano-Payment in API Request Headers
In the previous step, we created a payment claim. This looked something like this:
Once we copied our payment-claim, we're ready for the next step. To configure nano-payments in API request headers, the payment claims are embedded directly into the request headers. To do this, we select the "Authentication" box and add a custom API key with name **Payment-Claim** and add the copied payment claim into the "API Key" box:
After clicking save and updating our GPT, that's it! Our GPT is now ready to be used. When we ask it questions - in this case about XRPL - it will refer to the API we specified from our JSON spec and embed the payment claim in all headers to fund the API requests it makes. Magic!
Challenges and Lessons Learned
Chat GPT's Current Inability to Modify Payment-Claims Directly from User Messages
One of the key challenges encountered was Chat GPT's current inability to take messages directly from users' chat to modify payment-claims embedded in request headers. This limitation requires additional handling to ensure payment claims are correctly formatted and integrated.
Conclusion
Building a custom GPT capable of making nano-payments directly to APIs marks a significant step towards AI systems that interact autonomously with the economy. This development opens up new possibilities for micropayments and API integration, paving the way for more advanced and autonomous AI applications.
FAQs
Q1: What are nano-payments?
A: Nano-payments are micro-transactions facilitated by payment channels on blockchain networks, allowing for quick and low-cost transactions.
Q2: What is the JSON spec used for in this project?
A: The JSON spec is from by Open API to allow Chat GPT to understand the structure of the API we want it to use.
Q3: Can the payment claim system be used with other blockchain networks?
A: Currently, the system is limited to the XRPL, but it has the potential to be extended to support any blockchain-based currency in the future.
Q4: What are some real-world applications of this custom GPT?
A: Applications include pay-per-use APIs, content monetization through microtransactions, and handling micropayments for IoT device data exchanges.