Payments
TnsAI agents talk to other agents. Sometimes the other agent charges. The PaymentBroker SPI is the framework's answer to "how does an agent settle a payment without you, the human, in the loop?" — same surface for free internal calls (PaymentBroker.noOp()), real on-chain micropayments (X402PaymentBroker), or your own custom rail.
Pages
- x402 (HTTP 402 + EIP-3009) — Coinbase-led standard. Sub-cent USDC payments over Base. The first concrete adapter on the
PaymentBrokerSPI.
When to think about payments
You don't need a payment broker for free internal multi-agent traffic — the default is PaymentBroker.noOp() (the NoOpPaymentBroker singleton). Accountability machinery threads through untouched. Reach for a real broker when:
- Your agent calls third-party services that charge per request — premium MCP servers, paid embedding endpoints, paid weather/news feeds. With x402, the server returns HTTP 402 and your broker auto-settles the micropayment; the response comes back as if you'd called a free endpoint.
- Your agent offers a paid service to other agents outside your trust boundary. Quote the price, accept the signed authorisation, settle on-chain (or via Stripe, Lightning, etc. — once those adapters ship).
- You need an audit trail showing exactly how much each agent spent and on what. Every settlement emits an
AgentLiabilityRecordfor downstream compliance.
Architecture
Quote(payer, payee, service)
Settlement {Settled | Rejected | Expired | AlreadySettled}
│ ▲
▼ │
┌──────────────────────────────────────────────────────────────┐
│ PaymentBroker (SPI, tnsai-core) │
└──────────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────┼──────────────────────────┐
▼ ▼ ▼
PaymentBroker.noOp() X402PaymentBroker (future adapters)
- default (core) - tnsai-payments - Stripe
- free internal traffic - x402 / EIP-3009 - Lightning
- quotes at $0.00 - Base mainnet + Sepolia
- Wallet SPI for signingThe broker is the layer between your agent's chat loop and whatever rail moves the money. The rest of this section walks you through wiring it up.
Related
- Security: Accountability —
AgentLiabilityRecordaudit trail every broker emits to. - Security: Cost Governance — pair
CostBudget(broad LLM spend) withAuthorityScope.spendCeilingUSD(per-broker mandate) for layered controls. - Reference: SPI —
PaymentBrokercontract.
Bilingual embedding bench
tnsai-evaluation ships an opt-in multilingual retrieval bench (EmbeddingBenchRunner, @since 0.14.0 on TnsAI@c28d8783). It is in Maven Central 0.14.1. Default mvn test stays offline and does not call a model host.
x402 Payments
x402 is a Coinbase-led standard for HTTP-native micropayments. A server signals "this resource costs money" with a real HTTP 402; the client signs a one-time USDC transfer authorisation (EIP-3009), replays the request with the signature in a header, and the server validates and serves the response. Settlement happens on Base (EVM L2) at fractions of a cent per call.