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.
Public Beta — early access
Tollstile and its rails are implemented and tested against fakes, published test vectors, and reference implementations. The API and payment behavior may change before v1.0, and some rails are still experimental and may be unstable in production. Use the test rail during development and introduce live rails gradually. Nothing is on npm yet; each rail's page states its verification status.
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.
Tutorials
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.