Tollstile

Let subscribers through without paying

Give active subscribers free access to paid routes while everyone else pays per call.

Pre-release · planned API
import { payPerCall, subscriber } from "tollstile";
import { tollstile } from "@tollstile/hono";

const subscribers = subscriber({
  active: async (principal) => plans.isActive(principal.id),
});

app.get(
  "/v1/search",
  tollstile(toll.price("$0.01", { access: [subscribers, payPerCall()] }), {
    principal: (c) => (c.get("user") ? { id: c.get("user").id } : null),
  }),
  search,
);
  • Policies run in order. The first that grants access wins; payPerCall() asks for payment.
  • Callers without a principal are skipped by subscriber().
  • If access is set and no policy grants access or asks for payment, the request is denied with 403.
  • Subscriber access records no charge — there is no economic effect.

Combine with credits: access: [subscribers, credits({ balance }), payPerCall()].