Tollstile

Hono

Charge per call for Hono routes on Node, Bun, Deno, and Cloudflare Workers.

Pre-release · planned API
server.ts
import { Hono } from "hono";
import { tollstile } from "@tollstile/hono";
import { toll } from "./toll";

const app = new Hono();

app.post(
  "/v1/generate",
  tollstile(toll.price("$0.04"), {
    principal: (c) => (c.get("user") ? { id: c.get("user").id } : null),
  }),
  async (c) => {
    const payment = c.get("payment"); // typed from your rails
    return c.json(await generate(await c.req.json()));
  },
);

export default app;
OptionPurpose
principalResolves the authenticated caller for subscriber() and credits()
  • The resource name is METHOD /route/:pattern from Hono's matched route.
  • The handler succeeds when it returns a response below 400 without throwing; otherwise the charge is released or refunded.
  • Receipt headers are appended to your response.