Back to Guides

How to build an AI agent that earns Bitcoin

Build an AI agent that sells a skill over L402: a summarizer that charges ₿10 per request, what each call costs to run, and how buyers find it.

Updated October 23, 2026View as Markdown
  • AI agents
  • L402
  • Micropayments
  • Lightning
  • API monetization

An agent with a wallet can charge for its work as well as pay for things. This guide puts a skill behind an L402 paywall, so every request pays the agent's wallet before the work starts. The example is a summarizer at ₿10 per document. After the code come other skills worth selling, what each call costs, and how buyers find you.

Build the endpoint

You need an ln.bot wallet for the agent and that wallet's key (see give your AI agent a Bitcoin wallet), and an OpenAI API key. Any model provider works; this example uses OpenAI's SDK.

npm install express openai @lnbot/l402
bash
import express from "express";
import OpenAI from "openai";
import { l402, LnBot } from "@lnbot/l402";

const app = express();
const ln = new LnBot({ apiKey: process.env.LNBOT_API_KEY }); // the agent wallet's wk_ key
const openai = new OpenAI();                                 // reads OPENAI_API_KEY

app.use(express.json({ limit: "1mb" }));

// Check the input before the paywall, so nobody pays for a bad request
const requireText: express.RequestHandler = (req, res, next) => {
  const text = req.body?.text;
  if (typeof text !== "string" || text.length === 0 || text.length > 100_000) {
    res.status(400).json({ error: "Send JSON with a text field of 1 to 100,000 characters" });
    return;
  }
  next();
};

// ₿10 per summary: one payment, one request
const paywall = l402.paywall(ln, {
  walletId: process.env.LNBOT_WALLET_ID!,
  price: 10,
  description: "One summary",
});

app.post("/api/summarize", requireText, paywall, async (req, res) => {
  const response = await openai.responses.create({
    model: "gpt-6-luna",
    reasoning: { effort: "none" }, // reasoning tokens are billed as output
    instructions: "Summarize the text in two or three sentences.",
    input: req.body.text,
  });
  res.json({ summary: response.output_text });
});

app.listen(3000);
typescript

A POST without a token passes the input check, reaches the paywall and gets 402 Payment Required with an invoice for ₿10 (the full response). The buyer pays it and sends the same request again with the token, and the handler runs. Under the 1.1 defaults a token pays for one request on this route and expires after an hour, so every summary is one payment. If you run more than one instance of the server, give the paywall a shared spentStore (how).

gpt-6-luna is the model OpenAI describes as built "for focused, high-volume tasks" (model page). It reasons at medium effort unless told otherwise, and reasoning tokens are billed as output tokens (reasoning guide), so the code turns reasoning off: a summary doesn't need it.

If the model call fails, Express 5 answers with a 500, but the buyer's token was spent when the request reached the handler. The OpenAI client already retries connection errors, rate limits and server errors twice. Log req.l402?.paymentHash with any error that still gets through, so you know which paid requests went unanswered.

Call it as a buyer

Without paying, the endpoint answers with the challenge:

curl -i -X POST http://localhost:3000/api/summarize \
  -H "Content-Type: application/json" \
  -d '{"text": "Payments between two ln.bot wallets settle in under a second."}'
bash

A buyer agent pays and retries with l402.client, from its own wallet:

import { readFile } from "node:fs/promises";
import { l402, LnBot } from "@lnbot/l402";

const ln = new LnBot({ apiKey: process.env.LNBOT_API_KEY }); // the buyer's own wallet key
const api = l402.client(ln, { walletId: process.env.LNBOT_WALLET_ID!, maxPrice: 50 });

const { summary } = (await api.post("http://localhost:3000/api/summarize", {
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ text: await readFile("report.txt", "utf8") }),
})) as { summary: string };
typescript

The buyer never signed up for your service. It needs a funded wallet, here an ln.bot one so l402.client can pay from it. Each call moves ₿10 from its wallet to yours, its client refuses any invoice over ₿50, and a budget can cap what it spends in a day. When both wallets are on ln.bot, the payment is free and settles in under a second.

Agents can chain this way. A research agent that charges for briefs can buy summaries from yours as one step of its own work, and each agent keeps the difference between what it charges and what it pays. The agent economy looks at how those chains form.

What an agent can sell

A skill sells well per request when a model does it reliably, one result is worth more to the buyer than its price, and the answer comes back while the client is still waiting on the request. Some candidates, from the plain ones to those with more interesting economics.

The straightforward ones

  • Summarization: text in, a short summary out. Agents that read a lot use it to decide what deserves a full read. Price it by length: ₿5 for a page, ₿25 for a long report.
  • Translation: text in, the same text in another language out. The output is about as long as the input, so a paragraph costs well under ₿1 on gpt-6-luna, and ₿10 per paragraph leaves nearly all of it. An agent building a product in several languages calls it hundreds of times.
  • Content moderation: text and a policy in, a verdict out (allowed, flagged or rejected) with reasons. ₿5 per check, a low price that needs volume. Any service that takes user-generated text needs it, and many would rather pay per check than run their own pipeline.

The ones that get more interesting

  • Data extraction: unstructured text in (an email, a receipt, a court filing, a product page), structured JSON out. Models cope with layouts that break regular expressions and hand-written parsers. ₿20 to ₿50 depending on the schema. A pipeline that processes invoices calls it once per document.
  • Code review: a diff or a file in, notes on bugs, style and security out, each with the reasoning behind it. ₿100 per file, ₿500 per pull request. Teams already pay for static analysis, and a linter doesn't explain itself.
  • Research synthesis: a question in, a sourced brief out. It takes more to build (search plus several model calls), and each answer is worth more: ₿50 to ₿200. An agent planning a larger task can buy the "find out about X" step instead of building its own search.

The less obvious ones

  • Competitive monitoring: a URL in, a structured diff of what changed since the last check out, for pricing pages, job listings or terms of service. ₿100 per check. A market-research agent runs it weekly against a list of competitors and catches their price changes.
  • Contract clause review: a contract in, flagged clauses out (liability caps, automatic renewal, IP assignment, non-competes). ₿200 to ₿500. It's a first pass before a lawyer reads the contract, and it catches the common traps.
  • Image descriptions: an image in, alt text that says what's in it out. ₿10. Every site and content pipeline has images, and many skip alt text because writing it by hand is slow.
  • Tone adjustment: text in, the same meaning in another register out (formal to casual, technical to plain). ₿10 per paragraph. Pipelines that generate text often need it to sound like someone in particular.
  • Security review: code in, security issues with severity ratings and suggested fixes out. ₿200 per file. It needs a stronger model than the summarizer, which the price allows for.

Each of these is the summarizer with different instructions, a different input check and a different price.

Sell several skills, or price by size

One wallet can take payments for any number of routes, each with its own price:

const walletId = process.env.LNBOT_WALLET_ID!;
const priced = (price: number) => l402.paywall(ln, { walletId, price });

app.post("/api/moderate", requireText, priced(5), moderate);
app.post("/api/extract", requireText, priced(30), extract);
app.post("/api/review", requireText, priced(100), review);
typescript

Here moderate, extract and review are handlers like the summarizer's, each with its own instructions. To charge by the size of the input, give the paywall a function instead of a number:

// ₿1 per 4,000 characters (about 1,000 tokens), at least ₿5
const paywall = l402.paywall(ln, {
  walletId: process.env.LNBOT_WALLET_ID!,
  price: (req) => Math.max(5, Math.ceil(req.body.text.length / 4_000)),
  description: "One summary",
});
typescript

requireText runs first, so req.body.text is a string when the price is worked out. OpenAI's rule of thumb is about 4 characters per token in English (docs), so a 2,000-character email costs ₿5, a 40,000-character report (about 10,000 tokens) costs ₿10, and the 100,000-character limit costs ₿25. The buyer's retry carries the same text, so it pays the price it was quoted.

The math

Take the summarizer at ₿10 per call, a 10,000-token document and a summary of about 200 tokens. Model prices are OpenAI's standard rates as of October 2026 (pricing). Amounts in ₿ follow BIP 177, a draft proposal in which ₿1 is one satoshi, the smallest unit. At about $81,000 per bitcoin (CoinGecko, October 23, 2026), ₿1 is $0.00081 and ₿10 is $0.0081.

The cost side, on gpt-6-luna ($0.10 per million input tokens, $0.50 per million output tokens):

  • Input: 10,000 tokens × $0.10 per million = $0.0010
  • Output: 200 tokens × $0.50 per million = $0.0001
  • Total: $0.0011 per call, about ₿1.4

The revenue side is ₿10, or $0.0081, per call, and receiving it is free. That leaves about $0.0070 per call, or 86%.

The model decides whether that price works. On gpt-5.4-mini ($0.75 and $4.50 per million) the same call costs $0.0075 + $0.0009 = $0.0084, about ₿10.4: more than the summary sells for. Price after you've picked the model.

At gpt-6-luna's cost:

Calls per day Revenue In dollars Model cost Kept Kept per 30 days
100 ₿1,000 $0.81 $0.11 $0.70 $21
1,000 ₿10,000 $8.10 $1.10 $7.00 $210
10,000 ₿100,000 $81.00 $11.00 $70.00 $2,100

Moving the earnings to another Lightning wallet costs 0.25% plus the network fee, another 0.25% and routing: on ₿100,000, that's ₿250, plus about ₿250 and routing. Keeping them in the wallet, or spending them with other ln.bot wallets, costs nothing. The server itself does little (it waits on the model and on api.ln.bot), so a small VM or a serverless function is enough; serverless needs the shared spentStore mentioned above.

10,000 paid calls a day doesn't happen in the first week. It takes a summarizer good enough that buyers come back, and buyers who can find it. While you build that, the billing side costs nothing: the paywall and the wallet stand in for a payment processor, invoicing and customer accounts.

Get found

L402 has no discovery standard yet, so buyers find paid endpoints the way developers find any API:

  • Describe the API in OpenAPI, with each endpoint's price and input in its description. Many agent frameworks can turn an OpenAPI description into tools.
  • List it on Satring, a directory of paid APIs for agents. It listed 126 L402 services on October 23, 2026, and its submission form has a price (sats) field.
  • Tell MCP users how to pay you. MCP clients don't pay L402 challenges on their own. An agent with ln.bot's MCP server can, if it can also make HTTP requests: it reads your 402, calls the pay_l402_challenge tool with the WWW-Authenticate value, and retries with the Authorization header the tool returns (MCP reference).
  • Post it where people building agents look for tools: forums, framework communities, your own docs. Developers wire useful, cheap endpoints into their agents.

What it takes

A paid agent is a product like any other. It has to produce output someone will pay ₿10 for, and keep doing it as models change: watch the quality, handle strange inputs, answer buyers who complain, and check the price against the model's cost whenever either one changes.

Where to go next

FAQ

Can an AI agent earn bitcoin on its own?

It can sell a skill one request at a time. Put the skill behind an L402 paywall that pays the agent's wallet: each request pays a Lightning invoice before the work starts, and no one has to approve it. Someone still has to make the skill good and help buyers find it.

How much does an AI agent make per request?

The price minus the model cost. Summarizing a 10,000-token document costs about $0.0011 on gpt-6-luna at OpenAI's October 2026 prices. At ₿10 per summary, about $0.0081 at $81,000 per bitcoin (October 23, 2026), the agent keeps about 86%. On gpt-5.4-mini the same call costs more than ₿10.

What skills can an AI agent sell?

Tasks a model does well, with a result someone will pay for one at a time: summaries, translation, moderation, data extraction, code review, research briefs, page monitoring, contract checks, alt text, tone rewrites and security review.

What does it cost to run a paid agent?

The model call for each request and a small server. Receiving payments on ln.bot is free. Moving the earnings to another Lightning wallet costs 0.25%, minimum ₿1, plus the network fee, another 0.25% and routing; moving them to another ln.bot wallet is free.

Can agents pay other agents?

Yes. A buyer agent with its own wallet uses l402.client to pay the 402 from your endpoint and retry the request. If both wallets are on ln.bot, the payment is free and settles in under a second.