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

@bit-gpt/h402-proxy

v0.0.3

Published

h402 Payment Protocol proxy middleware for Express - monetize any API with crypto payments

Downloads

34

Readme

h402-proxy

Express middleware integration for the h402 Payment Protocol that enables you to monetize any external API with crypto payments. This package allows you to easily add paywall functionality to external services using the h402 protocol.

Installation

npm install @bit-gpt/h402-proxy

Quick Start

import express from "express";
import { h402Proxy, createRouteConfigFromPrice } from "@bit-gpt/h402-proxy";

const app = express();

// Proxy to Anthropic Claude with payment protection
app.use('/claude', h402Proxy({
  target: 'https://api.anthropic.com',
  routes: {
    '/v1/messages': createRouteConfigFromPrice('$0.03', 'base', '0xYourAddress')
  },
  headers: {
    'x-api-key': process.env.ANTHROPIC_KEY
  }
}));

app.listen(3000);

Configuration

The h402Proxy function accepts the following configuration:

Basic Configuration

interface ProxyConfig {
  /** Target URL to proxy requests to */
  target: string;
  
  /** h402 payment configuration for routes */
  routes: RoutesConfig;
  
  /** Headers to inject into proxied requests */
  headers?: Record<string, string>;
  
  /** Proxy-specific options */
  proxyOptions?: ProxyOptions;
  
  /** h402 facilitator configuration */
  facilitator?: FacilitatorConfig;
  
}

Route Configuration

Routes are configured using the same pattern as h402-express:

import { createRouteConfigFromPrice } from "@bit-gpt/h402-proxy";

const routes = {
  // Simple price string
  '/v1/messages': '$0.03',
  
  // Advanced configuration
  '/v1/chat/completions': createRouteConfigFromPrice('$0.05', 'base', '0xYourAddress'),
  
  // Multiple payment options
  '/premium/*': {
    paymentRequirements: [
      {
        scheme: "exact",
        namespace: "evm",
        tokenAddress: "0x...",
        amountRequired: 0.01,
        amountRequiredFormat: "humanReadable",
        networkId: "8453",
        payToAddress: "0x...",
        description: "Premium API access"
      }
    ]
  }
};

Proxy Options

interface ProxyOptions {
  /** Change the origin of the host header to the target URL */
  changeOrigin?: boolean;
  
  /** Rewrite the request path before proxying */
  pathRewrite?: (path: string, req: Request) => string;
  
  /** Request timeout in milliseconds (default: 30000) */
  timeout?: number;
  
  /** Follow redirects (default: false) */
  followRedirects?: boolean;
  
  /** Hook called before proxying the request */
  onProxyReq?: (proxyReq: ClientRequest, req: Request, res: Response) => void;
  
  /** Hook called when proxy response is received */
  onProxyRes?: (proxyRes: IncomingMessage, req: Request, res: Response) => void;
  
  /** Hook called when proxy encounters an error */
  onError?: (err: Error, req: Request, res: Response) => void;
}

Examples

Anthropic Claude

app.use('/claude', h402Proxy({
  target: 'https://api.anthropic.com',
  routes: {
    '/v1/messages': createRouteConfigFromPrice('$0.03', 'base', YOUR_ADDRESS)
  },
  headers: {
    'x-api-key': process.env.ANTHROPIC_KEY,
    'anthropic-version': '2023-06-01'
  }
}));

OpenAI

app.use('/openai', h402Proxy({
  target: 'https://api.openai.com',
  routes: {
    '/v1/chat/completions': '$0.05',
    '/v1/embeddings': '$0.01'
  },
  headers: {
    'Authorization': `Bearer ${process.env.OPENAI_KEY}`
  },
  proxyOptions: {
    timeout: 60000
  }
}));

Path Rewriting

app.use('/api', h402Proxy({
  target: 'https://backend.example.com',
  routes: { '/*': '$0.01' },
  headers: { 'Authorization': `Bearer ${process.env.SERVICE_KEY}` },
  proxyOptions: {
    pathRewrite: (path) => path.replace('/api', '/v2'),
    timeout: 30000
  }
}));