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

token-limiter

v1.0.0

Published

Framework-agnostic token budget monitoring and kill-switches for autonomous AI agents. Works with any LLM provider.

Readme

token-limiter

Token budget monitoring and kill-switches for autonomous AI agents. Zero dependencies.

npm install token-limiter

Quick start

import { tokenLimiter, fromOpenAI } from 'token-limiter';

const budget = tokenLimiter({ maxTokens: 500_000, maxCost: 5.00 });

const response = await openai.chat.completions.create({ model: 'gpt-4o', messages });
budget.record(fromOpenAI(response));

if (!budget.ok) console.log(budget.reason);

fromOpenAI() maps the response to { input, output, reasoning }. record() tracks it, checks the ceiling, runs the circuit breaker. ok tells you if the agent should continue.

Adapters

One adapter per provider. Each returns { input, output, reasoning }:

import { fromOpenAI, fromGemini, fromAnthropic, fromOllama, fromRaw } from 'token-limiter';

budget.record(fromOpenAI(response));     // OpenAI, Groq, Together, Fireworks, LM Studio
budget.record(fromGemini(response));     // Google AI Studio, Vertex
budget.record(fromAnthropic(response));  // Claude
budget.record(fromOllama(response));     // Ollama, any local model
budget.record(fromRaw(3200, 800, 5400)); // raw numbers

Works with any provider that returns token counts. If yours isn't listed, use fromRaw().

What tokenLimiter() gives you

budget.ok        // should the agent continue?
budget.reason    // why it stopped, or null
budget.usage     // { input, output, reasoning, total }
budget.cost      // { input, output, reasoning, total } in USD
budget.turns     // number of turns recorded
budget.history   // full turn history
budget.analyze() // run anomaly detection

Config

const budget = tokenLimiter({
  maxTokens: 500_000,          // token ceiling
  maxCost: 5.00,               // dollar ceiling
  maxDuplicateCalls: 3,        // identical tool calls before kill
  reasoningPctThreshold: 80,   // reasoning % to flag
  inputRate: 0.00125,          // $/1K input tokens
  outputRate: 0.01,            // $/1K output tokens
  reasoningRate: 0.0125,       // $/1K reasoning tokens
});

Events

budget.on('warning', (e) => console.log(e.message));   // 50%, 75%, 90% thresholds
budget.on('tripped', (e) => console.error(e.violations)); // circuit breaker fired

Individual modules

If you need more control, the internals are exported too:

import { TokenTracker, BudgetMonitor, KillSwitch, AnomalyDetector } from 'token-limiter';

Demo

npm run demo

Simulates 20 turns across healthy → degrading → rogue phases. Kill-switch trips when cost ceiling breaches.

Related

License

MIT © Hemanth.HM