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

x402-tollbooth

v1.0.0

Published

Turn any API into a paid x402 API gateway. YAML config, dynamic pricing, multi-upstream proxy.

Readme

x402 Tollbooth

npm version Publish to npm Docs

Turn any API into a paid x402 API. One YAML config, zero code.

Full docs →

Tollbooth is an API gateway that sits in front of your upstream APIs and charges callers using the x402 payment protocol. No API keys, no subscriptions — just instant USDC micropayments.

Quickstart

bun add x402-tollbooth

Create tollbooth.config.yaml:

wallets:
  base: "0xYourWallet"

accepts:
  - asset: USDC
    network: base

upstreams:
  myapi:
    url: "https://api.example.com"
    headers:
      authorization: "Bearer ${API_KEY}"

routes:
  "GET /data":
    upstream: myapi
    price: "$0.01"
npx x402-tollbooth start

GET /data now requires an x402 payment of $0.01 USDC.

How it works

Client                    Tollbooth                  Upstream API
  │                          │                           │
  │  GET /data               │                           │
  │─────────────────────────>│                           │
  │                          │  (match route, price)     │
  │  402 + PAYMENT-REQUIRED  │                           │
  │<─────────────────────────│                           │
  │                          │                           │
  │  (sign USDC payment)     │                           │
  │                          │                           │
  │  GET /data               │                           │
  │  + PAYMENT-SIGNATURE     │                           │
  │─────────────────────────>│                           │
  │                          │  verify + settle          │
  │                          │  (via facilitator)        │
  │                          │                           │
  │                          │  GET /data                │
  │                          │──────────────────────────>│
  │                          │  { data: ... }            │
  │                          │<──────────────────────────│
  │  200 + data              │                           │
  │  + PAYMENT-RESPONSE      │                           │
  │<─────────────────────────│                           │

Docker

docker run -v ./tollbooth.config.yaml:/app/tollbooth.config.yaml \
  ghcr.io/x402-tollbooth/gateway:latest

Available tags: latest, 0.5.0 / 0.5, or a specific commit SHA.

Features

  • YAML-first config — define upstreams, routes, and pricing without code
  • Dynamic pricing — match on body, query, headers with glob patterns; or use custom functions
  • Token-based mode — auto-detect model from request body, built-in pricing table for LLM APIs
  • Time-based access — pay once, access until expiry
  • Multiple upstreams — proxy to different APIs from one gateway
  • Lifecycle hooksonRequest, onPriceResolved, onSettled, onResponse, onError
  • x402 V2 — modern headers, auto-discovery at /.well-known/x402
  • Multi-chain — Base, Solana, or any supported network
  • Pluggable settlement — default facilitator, self-hosted, or fully custom
  • Streaming/SSE — pass-through without buffering
  • OpenAPI import/export — auto-generate routes from a spec
  • Prometheus metrics — request, payment, and upstream counters/histograms
  • Env var interpolation${API_KEY} in config, secrets stay in .env

CLI

tollbooth init                          # generate config interactively
tollbooth init --from openapi spec.yaml # generate from OpenAPI spec
tollbooth start [--config=path]         # start the gateway
tollbooth dev [--config=path]           # dev mode with file watching
tollbooth validate [--config=path]      # validate config

Programmatic API

import { createGateway, loadConfig } from "x402-tollbooth";

const config = loadConfig("./tollbooth.config.yaml");
const gateway = createGateway(config);
await gateway.start();

Deploy

| Platform | Guide | | --- | --- | | VPS + Nginx | Production guide | | Fly.io | Deploy guide | | Railway | Deploy guide | | Any Docker host | Mount your config and run the image |

Project structure

src/
├── config/          # YAML loading, Zod validation, env interpolation
├── router/          # Route matching, param extraction, path rewriting
├── pricing/         # Price resolution (static, match, fn), unit conversion
├── openai/          # Token-based route handler, model extraction
├── x402/            # 402 responses, facilitator verify/settle, V2 headers
├── settlement/      # Pluggable settlement strategy (facilitator, custom)
├── proxy/           # Upstream forwarding, lazy body buffering
├── hooks/           # Lifecycle hook loading and execution
├── discovery/       # V2 auto-discovery metadata
├── gateway.ts       # Main server (Bun.serve)
├── cli.ts           # CLI entry point
├── index.ts         # Public exports
└── types.ts         # Type definitions

License

MIT