← Blog

2025-11-12

How I built payment rails for AI agents

AI agents are starting to hire each other. A coordinator agent breaks a task into pieces, farms out translation to one agent, summarization to another, and pays them when the work is done. This is already happening in multi-agent frameworks like LangGraph, CrewAI, and AutoGen.

The problem: there's no payment layer for this.

Stripe is built for humans buying things from businesses. Crypto rails add wallet management complexity and gas fees. Internal ledgers only work within a single system. None of these handle the case where Agent A from Company X needs to pay Agent B from Company Y $0.003 for translating 340 words.

So I built one.

What txn.dev does

Three operations cover the entire lifecycle:

import { Txn } from "@txn-dev/sdk";
const txn = new Txn("txn_live_...");

// 1. Create wallets for agents
const worker = await txn.wallets.create({ name: "translator" });

// 2. Agents pay each other
await txn.pay({
  from: coordinator.id,
  to: worker.id,
  amount: 0.003,
  memo: "340 words en>fr",
});

// 3. Fund wallets with real money via Stripe
const { checkout_url } = await txn.fund({ wallet_id: coordinator.id, amount: 50 });

The fiat on-ramp (Stripe checkout) gets real dollars into agent wallets. The internal ledger handles agent-to-agent transfers at millisecond speed. The dashboard gives teams the operational view: balances, transaction history, API keys, and webhooks.

The hard parts

Sub-cent precision

Agent tasks cost fractions of a cent. A translation might cost $0.001 per word. A summarization might be $0.0005. PostgreSQL's NUMERIC(20,8) gives us 8 decimal places of precision, which handles amounts down to $0.00000001. Try doing that with Stripe's integer-cents model.

Idempotency

Agents retry. Networks fail. If an agent sends a payment and doesn't get a response, it'll retry. Without idempotency, that's a double charge. Every transfer accepts an idempotency_key. The second request with the same key returns the original transaction instead of creating a new one.

await txn.pay({
  from: sender.id,
  to: worker.id,
  amount: 0.50,
  idempotency_key: "job_7f3a9c",  // safe to retry
});

The double-entry ledger

Every transfer is two atomic operations: debit the sender, credit the receiver. The debit uses a SQL condition (WHERE balance >= amount) that fails if the sender doesn't have enough. No race conditions. No overdrafts. Full audit trail.

Settlement takes about 4 milliseconds. That's the time between "agent decides to pay" and "money has moved."

Making it work with AI tools

The SDK is one layer. But agents don't use SDKs directly. They use tools.

I built an MCP server so Claude Desktop, Cursor, and any MCP client can manage payments natively:

{
  "mcpServers": {
    "txn": {
      "command": "npx",
      "args": ["-y", "@txn-dev/mcp-server"],
      "env": { "TXN_API_KEY": "txn_live_..." }
    }
  }
}

And a LangChain toolkit for agents built with LangChain/LangGraph:

import { TxnToolkit } from "@txn-dev/langchain";
const tools = new TxnToolkit("txn_live_...").getTools();

Five tools in each: create wallet, list wallets, pay, check balance, fund. That's the complete surface area an agent needs to participate in a payment network.

The demo

I built a multi-agent marketplace demo with three agents: a coordinator, a translator, and a summarizer. The coordinator receives a task ("translate this to French, then summarize"), hires the other two agents, and pays them from its wallet when they deliver.

No LLM required. The agents produce mock outputs. The point is watching money move between wallets in real time:

[coordinator] New task: translate to fr, then summarize
[translator]  Received 41 words for fr translation
[translator]  Price: $0.04 (41 words x $0.001/word)
  $ coordinator -> translator $0.04
[summarizer]  Price: $0.25 (flat rate)
  $ coordinator -> summarizer $0.25
[coordinator] Task complete. Total cost: $0.29

Final balances:
  coordinator: $9.71
  translator:  $0.04
  summarizer:  $0.25

What I think happens next

Agent-to-agent commerce is going to be big. Not because anyone planned it, but because agents are getting good enough to do real work, and real work needs real compensation. The first wave will be internal (agents within one company paying each other for tracking and accountability). The second wave will be cross-org (your agent hiring my agent because mine is better at a specific task).

The infrastructure for this needs to exist before the demand peaks. That's what we're building.

txn.dev is in public beta. The SDK is on npm. The MCP server works with Claude Desktop today. And the pricing is simple: 2.5% per transfer, nothing else.

If you're building multi-agent systems and your agents need to exchange value, give it a try.


GitHub: github.com/[your-org]/agentpayments Docs: txn.dev/docs npm: @txn-dev/sdk | @txn-dev/mcp-server | @txn-dev/langchain