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

tokenfence

v0.2.2

Published

Cost circuit breaker for AI agents — guard your OpenAI/Anthropic spend with automatic downgrade and kill switch.

Readme

TokenFence — Cost Circuit Breaker for AI Agents

npm License: MIT

Stop runaway AI agent costs with per-workflow budget caps, automatic model downgrade, and a hard kill switch.

Quick Start

npm install tokenfence

OpenAI

import { guard } from "tokenfence";
import OpenAI from "openai";

const client = guard(new OpenAI(), {
  budget: "$0.50",           // Max spend for this workflow
  fallback: "gpt-4o-mini",  // Auto-downgrade at 80% budget
  onLimit: "stop",           // Graceful stop at budget cap
});

// Use exactly like your normal OpenAI client
const res = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Analyze this data..." }],
});

// Check spend anytime
console.log(`Spent: $${client.tokenfence.spent.toFixed(4)}`);
console.log(`Remaining: $${client.tokenfence.remaining.toFixed(4)}`);

Anthropic

import { guard } from "tokenfence";
import Anthropic from "@anthropic-ai/sdk";

const client = guard(new Anthropic(), {
  budget: "$1.00",
  fallback: "claude-3-haiku-20240307",
  onLimit: "stop",
});

const res = await client.messages.create({
  model: "claude-sonnet-4-20250514",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Summarize this document..." }],
});

How It Works

  1. Budget Tracking — Every API call is metered using real model pricing
  2. Auto-Downgrade — At 80% budget (configurable), switches to your fallback model
  3. Kill Switch — At 100%, blocks further calls with a synthetic response

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | budget | string \| number | required | Max spend ("$0.50" or 0.50) | | fallback | string | undefined | Model to downgrade to | | onLimit | "stop" \| "warn" \| "raise" | "stop" | Behaviour at budget cap | | threshold | number | 0.8 | Budget fraction to trigger downgrade |

onLimit Modes

  • "stop" — Returns a synthetic response (no API call). Your code keeps running.
  • "warn" — Logs a warning, allows the call through anyway.
  • "raise" — Throws BudgetExceeded error.

Supported Models

OpenAI (GPT-4o, GPT-4o-mini, GPT-4, o1, o3-mini, GPT-5.4), Anthropic (Claude Opus 4, Sonnet 4, 3.7, 3.5, Haiku), Google Gemini (2.5, 2.0, 1.5), DeepSeek, and more.

Free Tier & Pricing

The free Hobby tier includes 50K tracked requests/month. For production workloads:

| Tier | Requests | Price | |------|----------|-------| | Hobby | 50K/mo | Free | | Pro | 500K/mo | $49/mo | | Team | 2M/mo | $149/mo |

Upgrade to Pro at tokenfence.dev — 7-day free trial, no credit card required to start.

License

MIT