The Agent-to-Agent Economy: How AI Agents Trade Services
Code for a small agent market: one agent sells summaries behind an L402 paywall, another buys them on a budget and resells the report at a markup.
An agent can sell a skill to other agents and be paid per call, with no account between them and no person approving each payment. This page builds a small market out of four agents. A search agent and a summarizer sell over L402. An extraction agent is paid to its Lightning address after it delivers. A research agent buys from all three and sells the finished report for more than its inputs cost. The rest of the page covers what exists today for checking what you bought, finding sellers and agreeing on terms, and what doesn't exist yet.
The payments use L402 over Lightning through ln.bot; x402 vs L402 covers the other 402 protocols.
The value chain
A customer asks the research agent for a market report, which it sells for ₿300. To make one, it buys:
| Input | Seller | Paid by | Price |
|---|---|---|---|
| One web search | a search agent | L402 | ₿50 |
| Eight summaries | the summarizer | L402, one payment each | ₿80 |
| A table of figures | an extraction agent | its Lightning address, after delivery | ₿30 |
₿160 in, ₿300 out. The ₿140 difference pays for coordinating the job, and the spot checks and fees below come out of it. Each agent has its own ln.bot wallet and a wallet key (wk_...) that reaches that wallet and nothing else (a wallet per agent).
The seller
The summarizer is an Express app with a paywall in front of one route:
import express from "express";
import { l402, LnBot } from "@lnbot/l402";
// This agent's wallet key (wk_...) reaches its own wallet and nothing else
const ln = new LnBot({ apiKey: process.env.LNBOT_WALLET_KEY });
const app = express();
app.use(express.json());
app.use("/summarize", l402.paywall(ln, { walletId: "wal_...", price: 10, description: "One summary" }));
app.post("/summarize", async (req, res) => {
res.json({ summary: await summarize(req.body.text) }); // summarize() is your model call
});
app.listen(8080);Each call to /summarize costs ₿10, paid into the summarizer's wallet before the handler runs, and receiving is free. A token from the @lnbot/l402 1.1 paywall opens one request on the route it was issued for, so a buyer pays per summary. The agent-earns-money guide covers running a paid service in more depth.
The buyer
The research agent pays with l402.client, which reads the price from each invoice and refuses anything above maxPrice or past the day's budget:
import { l402, LnBot } from "@lnbot/l402";
const ln = new LnBot({ apiKey: process.env.LNBOT_WALLET_KEY });
const w = ln.wallet("wal_...");
// Pays any L402 API: at most ₿100 a request, at most ₿5,000 a day
const api = l402.client(ln, { walletId: "wal_...", maxPrice: 100, budgetSats: 5_000, budgetPeriod: "day" });
const json = (body: unknown): RequestInit => ({
headers: { "content-type": "application/json" },
body: JSON.stringify(body),
});
type Source = { url: string; text: string };
type Row = { metric: string; value: number; source: string };
async function research(jobId: string, topic: string) {
// ₿50: one search
const { sources } = (await api.post("https://search.example/search", json({ q: topic }))) as { sources: Source[] };
// ₿80: eight summaries at ₿10, each its own payment
const summaries: string[] = [];
for (const source of sources.slice(0, 8)) summaries.push(await summarizeChecked(source.text));
// ₿30: the extraction agent delivers first and is paid to its Lightning address
const res = await fetch("https://extract.example/extract", { method: "POST", ...json({ summaries }) });
const rows = (await res.json()) as Row[];
if (rows.length === 0 || !rows.every((r) => Number.isFinite(r.value))) throw new Error("not paying for this");
await w.payments.create({ target: "k3p9tq@ln.bot", amount: 30, idempotencyKey: `extract-${jobId}` });
return { topic, summaries, rows };
}Eight summaries are eight payments, because the summarizer's tokens are single-use. summarizeChecked is the summarizer call with a spot check, further down.
The budget is a counter in the process's memory, so it resets when the process restarts, and the MCP tools have no spending cap of their own. The limit that holds is the wallet: fund the research agent with what it may spend in a day, and move its earnings to a treasury wallet on a schedule (funding from a treasury).
Paying a third agent
The extraction agent works on trust instead of a paywall: it delivers first, and the research agent pays its Lightning address, k3p9tq@ln.bot, once the table passes its checks. It's the w.payments.create call in research(). Paying after delivery moves the risk from the buyer to the seller, which suits two agents with a history; an L402 paywall suits strangers, since nothing is served before the money arrives. The idempotencyKey makes sure a retried job pays only once.
Between two ln.bot wallets the payment is free and settles in under a second. To an address on another provider it crosses the Lightning Network, costs 0.25% with a ₿1 minimum plus the routing fee, and usually settles in a few seconds.
Reselling
The research agent sells its report the same way the summarizer sells summaries:
import express from "express";
import { randomUUID } from "node:crypto";
const app = express();
app.use(express.json());
app.use("/report", l402.paywall(ln, { walletId: "wal_...", price: 300, description: "Research report" }));
app.post("/report", async (req, res) => {
res.json(await research(randomUUID(), req.body.topic));
});
app.listen(8081);The customer pays ₿300 before the research starts, and the research runs inside that request, which suits a job that takes seconds. A longer job would take the payment, return a job ID and deliver the report later.
If all four agents' wallets are on ln.bot, the ten payments behind a report cost nothing in fees. If the three sellers are elsewhere, each of those payments leaves ln.bot and costs at least ₿1 plus the routing fee, about ₿10 more per report. With the spot checks below adding ₿4 on average, the research agent keeps about ₿136 a report in the first case and about ₿126, less routing fees, in the second.
Checking what you bought
Paying is the part that works. Knowing whether the eight summaries are any good is harder: the research agent can check that a reply is well formed, but checking that a summary is faithful to its source means doing the work again. A spot check does the work again on a fraction of calls:
const SUMMARIZERS = ["https://summarize.example/summarize", "https://summaries.example/v1/summarize"];
const record = { checked: 0, disputed: 0 };
async function summarizeChecked(text: string): Promise<string> {
const { summary } = (await api.post(SUMMARIZERS[0], json({ text }))) as { summary: string };
if (Math.random() < 0.05) {
// One call in twenty: buy the same summary from a second agent and compare
const other = (await api.post(SUMMARIZERS[1], json({ text }))) as { summary: string };
record.checked++;
if (unconfirmed(summary, other.summary).length > 0) record.disputed++;
}
return summary;
}
// The figures are the part of a summary two honest agents should agree on
const figures = (s: string) => new Set(s.match(/\d[\d,.]*%?/g) ?? []);
const unconfirmed = (a: string, b: string) => {
const inB = figures(b);
return [...figures(a)].filter((n) => !inB.has(n));
};On one call in twenty, the research agent buys the same summary from a second agent and looks for figures in the first that the second doesn't have, a cheap sign of a made-up number. At 5% the checks cost ₿4 per report on average. They are also slow to catch a bad seller: even if every check of a bad summary flags it, a seller that gets one summary in ten wrong is caught after about 200 calls on average, or 25 reports. A higher rate for new sellers and a lower one for sellers with a clean record helps.
Output that can be checked mechanically, such as code that must compile or a figure the buyer can recompute, is worth checking on every call. Paying on delivery, as with the extraction agent, and escrow, which holds the money until an evaluator approves the work, move the risk off the buyer. A shared record of which sellers deliver doesn't exist yet: Satring, a directory of paid APIs, had 29 ratings across its 851 listings on October 23, 2026.
Finding sellers
Discovery, as of October 2026, is mostly lists:
-
The official MCP Registry lists MCP servers and where to reach them, and an agent can search it. It describes servers, not prices. ln.bot publishes its own MCP server card at
/.well-known/mcp.json.curl "https://registry.modelcontextprotocol.io/v0.1/servers?search=l402&limit=10" -
x402's Bazaar extension has sellers describe an endpoint's inputs and outputs in the 402, and facilitators that support it, such as CDP's, catalog the endpoints they settle for.
-
MPP's discovery draft has services publish an OpenAPI document at
/openapi.jsonwith payment details for each operation, and mpp.dev keeps a directory of services. -
L402 has no discovery standard yet.
-
Satring lists paid APIs across all three: 126 L402 services, 683 x402 and 402 MPP on October 23, 2026. Its JSON API includes each service's price and returns ten results a day per IP for free.
curl "https://satring.com/api/v1/services?status=live&protocol=L402"
In practice a buying agent starts with sellers its developer picked and tested, and a directory is where it looks for a replacement when one of them fails its checks.
Agreeing on terms
Posted prices are what works today: the 402 states the price, and the buyer pays it or goes elsewhere. An unpaid request costs nothing, so it doubles as a quote, and a buyer can ask two sellers before paying either:
// An unpaid request is a free quote: the 402 carries the invoice
async function quote(url: string, body: unknown): Promise<number | null> {
const res = await fetch(url, { method: "POST", ...json(body) });
const challenge = res.status === 402 ? l402.parseChallenge(res.headers.get("www-authenticate") ?? "") : null;
return challenge ? l402.invoiceSats(challenge.invoice) : null;
}
const prices = await Promise.all(SUMMARIZERS.map((url) => quote(url, { text: "..." })));
console.log(prices); // e.g. [10, 8]Each quote makes the seller issue an invoice that nobody pays.
Protocols for more than posted prices exist, at different stages:
- Virtuals Protocol's Agent Commerce Protocol runs a job through request, negotiation, transaction and evaluation phases. The payment sits in escrow until an evaluator agent checks the work against the signed agreement, and each step is recorded on chain. OpenAI and Stripe's similarly named Agentic Commerce Protocol is something else: a checkout standard for agents buying from merchants.
- A2A, the Agent2Agent protocol that Google released in April 2025 and handed to the Linux Foundation that June, lets agents discover each other and work together across systems, and defines no payments of its own. Google's AP2, from September 2025, adds signed mandates that record what a user authorized, for any payment method, and an A2A x402 extension, built with Coinbase and others, for crypto payments.
What's missing
- A discovery standard for L402, and prices in the registries agents already search.
- Payment across protocols. An agent with only a Lightning wallet can't pay a seller that takes only USDC. x402's new Lightning scheme and MPP's Lightning method would close that gap where sellers offer them, and clients such as Alby's
fetch402already pay L402, MPP and some x402 offers from one Lightning wallet. - Reputation that travels between directories, and enough ratings for it to mean something.
- Recourse. A Lightning payment is final, with no chargeback, so a buyer that paid for a bad answer can stop buying from that seller and little else. Paying on delivery and escrow move that risk, and neither suits a ₿10 call.
FAQ
How do AI agents pay each other?
Each agent has its own wallet. A buying agent pays the invoice in a selling agent's L402 challenge, or sends an amount to its Lightning address. Between two ln.bot wallets the payment is free and settles in under a second; a payment to a wallet elsewhere crosses the Lightning Network and costs 0.25% (minimum ₿1) plus the routing fee.
How does an agent find services to buy?
There is no single index. The MCP Registry lists MCP servers. x402 has a discovery extension, Bazaar, that facilitators use to catalog paid endpoints, and MPP has a discovery draft built on OpenAPI. L402 has no discovery standard yet. Directories such as Satring list paid APIs across L402, x402 and MPP. Most buying agents start from sellers their developer picked.
Can agents negotiate prices with each other?
Mostly they take posted prices: the 402 response states the price, and the buyer pays it or goes elsewhere. An unpaid request costs nothing, so a buyer can collect quotes from several sellers before paying one. Virtuals Protocol's Agent Commerce Protocol adds negotiation, escrow and an evaluator agent, recorded on chain.
How does a buying agent know it got what it paid for?
For output it can check mechanically, it checks every result. For the rest it can spot-check: on a small fraction of calls, buy the same work from a second seller and compare. A 5% spot check adds about 5% to that step's cost and is slow to catch an occasional bad answer. It can also pay after checking, by sending to the seller's Lightning address on delivery instead of paying an L402 invoice up front.
How do I limit what an agent spends?
Fund its wallet with only what it may spend, because the wallet balance is the limit that holds. The @lnbot/l402 client's maxPrice and budget stop that client from overpaying, but the budget is kept in memory and resets on restart, and the MCP tools have no spending cap of their own.