Introduction
Tollstile is open-source payment middleware for APIs, MCP tools, and AI agents.
Tollstile adds paid access to any API route or MCP tool. Define who pays, how much, and which payment protocols you accept — Tollstile handles quotes, verification, replay protection, receipts, refunds, and reconciliation, without taking custody of your funds or your data.
import { createTollstile, memoryLedger, testRail } from "tollstile";
import { tollstile } from "@tollstile/hono";
const toll = createTollstile({ rails: [testRail()], ledger: memoryLedger() });
app.get("/weather", tollstile(toll.price("$0.01")), (c) => c.json({ forecast: "clear" }));An agent that calls /weather without paying gets 402 Payment Required with a signed quote and an offer for every rail you accept. An agent that pays gets the response, and your ledger records the charge.
Pre-release
The core, the test rail, the memory ledger, and the Hono adapter are implemented. Live rails (x402, MPP, L402, KYAPay), SQL ledgers, and the MCP, Next.js, and Express adapters are in development. Pages for those say so.
What you get
One line to price
Put a price next to the route or tool it guards.
Quotes
The price the payer saw is the price charged, even on dynamic routes.
Credits and subscriptions
Subscribers pass free; credits are reserved, then committed or released.
Spend limits
Cap calls and spend per payer.
Pay for what ran
Authorize a maximum, settle what the handler used.
No duplicate charges
Every charge is a state machine with idempotent operations and reconciliation.
How it fits
request ─► adapter ─► access policies ─► rail verification ─► requirements ─► handler
subscriber x402 · MPP · limit ·
credits L402 · KYAPay verifiedAgent ·
payPerCall userMandate
│
▼
ledger: authorizations · charges · claims- Rails decide how an agent pays.
- Access policies decide whether a caller has to pay.
- Requirements add conditions every admitted request must meet.
- The ledger is your operational record, reconciled with each provider.
Using a coding agent?
Point it at /llms.txt and the coding agents guide, or ask it directly:
Add $0.05 pay-per-call pricing to this Hono endpoint using Tollstile.