Inspired by Hivemind’s thesis on “How (Actually) Open AI Wins,” this series will explore how AI companies and projects can harness the power of the Lightning Network to push innovation and what tools builders can use to build this future.
In this third and final part of the series, we’ll look at the tools available for builders to create the tools we’ve mentioned in parts 1 and 2. But first, a quick recap.
Recap
In the first part of our series, we delved into foundational training, the initial phase in training AI models. These models learn to predict the next word in a sentence using vast training data. However, the process is very expensive, resulting in high barriers to entry. The advent of the Bitcoin and Lightning Network could help democratize this process, potentially enabling distributed training over a federation of contributors rewarded for their computational input.
Following foundational training, AI models undergo a process of fine-tuning, where they are further trained on a narrower dataset. This refines the broad abilities gained in foundational training to more specific applications. Some fine-tuning processes involve human reviewers. Using Bitcoin and Lightning Network could create an incentive mechanism for reviewers.
Once these models are fine-tuned, they are ready to be used. To be able to compute answers to prompts, AIs need a lot of computing power, which requires expensive hardware. Ordinary people must rely on big companies to use AI, but this doesn't have to be the case. Owners of high-end computer hardware could rent their computing power in exchange for Bitcoin over the Lightning Network, enabling a more decentralized solution.
In the second part of the series, we looked at how Bitcoin and the Lightning Network can act as a coordination tools for AI agents, enabling them to pay for external services and data. Currently, AI agents are constrained by their inability to interact with paid services. Credit card-based subscription models don't fit this use case. Lightning payments are the optimal solution, enabling microtransactions and fast payments in pay-per-use business models. There’s even an HTTP status code invented in the 90s called 402 - Payment Required that was mostly forgotten but is now coming back to life as developers are starting to integrate AI services with the Lightning Network.
Tools
Curiously enough, machine-to-machine payments is what initially piqued Olaoluwa – Lightning Labs CTO – interest in Bitcoin. Lightning Labs is pushing innovation to bridge the gap between Bitcoin and AI. Let’s take a look at the tools currently being developed.
L402 Protocol
L402, previously known as LSAT, is a protocol designed to enable service charging and user authentication. The protocol merges the strengths of two technologies: Macaroons for advanced authentication and the Lightning Network for efficient payments. With this tool, API keys are Macaroons that become valid only when combined with a cryptographic secret. This secret is obtained as a preimage via payment of a Lightning Network invoice, which is tied to the Macaroon by its payment hash. A service can distribute Macaroons and Lightning Network invoices to potential customers. The L402 protocol is essentially a means to authenticate and charge for API requests using the Lightning Network.
In our previous discussions, we highlighted a limitation faced by AI agents: their inability to engage with paid services due to the lack of a suitable payment mechanism. This is where the L402 protocol comes into play. It equips AI agents with the capability to handle monetary transactions, thereby facilitating their interaction with paid charging services.
Implementing the L402 protocol transitions the traditional credit card subscription models towards more flexible pay-per-use models. As mentioned, this transition holds significant advantages, enabling a more efficient and targeted use of services based on the AI's specific needs.
Moreover, Bitcoin can function as a means to coordinate operations among a network of AI agents, each with its specialized role. Just as money streamlines cooperation and specialization in human society, Bitcoin could do the same for a complex ecosystem of AI agents. With the L402 protocol enabling these transactions, we're set to witness a new level of interactivity and efficiency in AI.
You can read the official documentation here to build tools with the L402 protocol.
Aperture
Aperture is a reverse proxy that serves as a payment and authentication gateway for APIs powered by the Lightning Network. A reverse proxy is a server that sits between client devices and a web server, forwarding client requests to the web server and returning the server's responses to the clients. When a client device, such as your computer or smartphone, requests to access a website, it's not directly communicating with the website's server. Instead, the request goes to the reverse proxy, which then forwards the request to the server. Once the server has processed the request and generated a response, it sends it back to the reverse proxy, which then forwards the response to the client device.
Aperture checks the validity of access tokens generated by the L402 protocol and forwards requests to the respective servers. It is currently used in Loop and Pool, two products developed by Lightning Labs. In essence, this tool enables one to adapt any API into a pay-per-use API quickly.
In the context of AI, this can restrict access to an LLM prompt only for the users who paid for that access. The latest version of Aperture supports dynamic pricing, enabling requests prices for the prompt to react based on the query's model type, query length, or context window. This can also be used to empower owners of high-end hardware to charge for running queries on their hardware instead of making users rely on the services of private companies.
There are many more possible use cases. Your imagination is the limit. You can find its documentation here.
LangChainBitcoin
According to their website, LangChain is a framework for developing applications powered by language models. It enables applications that can connect a language model to other data sources and allow a language model to interact with its environment. In other words, it enables the chaining of language models.
Lightning Labs developed a wrapper for this framework, LangChanL402, that allows it to learn how to use an API through its documentation and interact with it with L402. The only thing missing is giving the AI agent the ability to hold, send and receive Bitcoin, and that’s exactly what LangChainBitcoin achieves. LangChainBitcoin is a suite of tools that enables LangChain agents to interact directly with Bitcoin and the Lightning Network. Developers can use this tool to create agents capable of holding, sending, and receiving Bitcoin, both on-chain and with Lightning.
You can find the source code of LangChainBitcoin here.
Voltage Nodes
If you’re a developer and want to experiment with Lightning and AI, you can use a Voltage Node to get access to the Lightning Network quickly. It’s the quickest way to deploy your Lightning project for people to use.