npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tuppence/http402

v0.1.1

Published

Put a price on an API route or an MCP tool: HTTP 402 with Tuppence receipts, verified offline.

Readme

@tuppence/http402

Put a price on an API route in one line, and let people and agents pay for it.

import { Tuppence } from "@tuppence/node";
import { http402 } from "@tuppence/http402";

const tuppence = new Tuppence(process.env.TUPPENCE_SECRET_KEY!);

app.get(
  "/v1/report",
  http402({ tuppence, price: 50, currency: "gbp", account: "acct_…" }),
  (req, res) => res.json(buildReport()),
);

What the caller sees

An unpaid request gets 402 Payment Required:

{
  "error": { "type": "payment_required", "code": "payment_required", "message": "…" },
  "price": 50,
  "currency": "gbp",
  "resource": "GET /v1/report",
  "payment_id": "pay_…",
  "accepts": [{ "type": "card_link", "url": "https://pay.tuppence.ai/pay/pay_…#…" }],
  "receipt": {
    "url": "https://api.tuppence.ai/public/payments/pay_…",
    "header": "Tuppence-Client-Secret",
    "client_secret": "…"
  }
}

with a Link: <…>; rel="payment" header. The caller pays at the URL, fetches receipt.url with the Tuppence-Client-Secret header, and retries with

Authorization: Tuppence-Receipt <receipt_token>

and gets the resource. A caller who retries before paying gets the same payment, not a new one each time.

Why it is safe

  • Verified offline. The receipt is a JWT signed by Tuppence (EdDSA); it is checked against Tuppence's published keys (/.well-known/jwks.json, cached). No call to Tuppence on the hot path.
  • Bound to what was bought. The receipt names its resource (default METHOD /path) and amount: a 1p receipt for another route opens nothing here.
  • Used once. Its jti is remembered until it expires (fifteen minutes). The default store is in memory. Running more than one process? Pass a shared store ({ claim(jti, expiresAt) }, e.g. Redis SET NX EX).
  • Paid to you. Pass account and receipts paid to anyone else are refused.

Credits: agents paying from prepaid balance (no card per call)

Give the route a meter priced the same, and your customers' agents can pay from their prepaid credit instead of a card:

app.get("/v1/report", http402({ tuppence, price: 50, currency: "gbp", credits: { meter: "report" } }), handler);

Your server mints the agent a token for its customer, capped and short-lived:

const { token } = await tuppence.request("POST", `/v1/credits/${customerId}/tokens`, {
  body: { max_amount: 1000, expires_in: 3600 },
});

and the agent sends Authorization: Tuppence-Credits <token> (with an Idempotency-Key, so a retried request is one use, not two). Tuppence enforces the cap and the expiry as it draws the credit; past either, the agent gets a 402 saying why (credit_token_limit, credit_token_expired, insufficient_credits with a topup_url).

Other frameworks

// Next.js route handlers, Hono, Bun, Deno, Workers
export const GET = withPayment({ tuppence, price: 50, currency: "gbp" }, async (req, paid) =>
  Response.json(await buildReport()),
);

// An MCP tool: an optional `receipt` argument; without it the agent is told where to pay
server.tool(
  "deep_research",
  { topic: z.string(), receipt: z.string().optional() },
  paidTool({ tuppence, price: 200, currency: "gbp", name: "deep_research" }, async ({ topic }) => ({
    content: [{ type: "text", text: await research(topic) }],
  })),
);

// Anything else: the framework-free core
const decide = payWall({ tuppence, price: 50, currency: "gbp" });
const decision = await decide({ method, path, authorization, caller });