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

backstop-ai

v0.6.0

Published

In-process LLM guardrails for the OpenAI SDK — drop-in budget, priority admission, AIMD concurrency, circuit breaker, retry, fallback chains, caching, hooks, audit, and agent guardrails, mirroring the Python backstop.wrap().

Downloads

154

Readme

backstop-ai

In-process LLM guardrails for the OpenAI SDK — a TypeScript port of the Python backstop wrap() API.

One drop-in call wraps your existing OpenAI client and adds:

  • Budget enforcement — reserve/commit token budget per request, in-process.
  • Circuit breaker — trip open after repeated failures, then probe recovery.
  • Automatic retry with exponential backoff on 429/5xx.
  • In-process fallback model — retry once against a backup model when the circuit opens (no proxy, no extra infra).
npm install backstop-ai openai
import OpenAI from "openai";
import { wrap } from "backstop-ai";

const client = wrap(new OpenAI(), 50_000, {
  fallbackModel: "gpt-4o-mini",
});

const res = await client.chat.completions.create({
  model: "gpt-4.1-mini",
  messages: [{ role: "user", content: "Hello." }],
});

How it works

wrap() patches client.chat.completions.create (the only call-site you use) and runs every request through a budget ledger + circuit breaker before calling the original method. Your code does not change. Budget reconciliation uses the provider's usage when available and a chars/4 heuristic otherwise.

Config

| Option | Default | Meaning | | ------------------- | --------- | ---------------------------------------------------- | | maxWrapSessions | 0 | Soft cap on active sessions (warning only). | | priorityHeader | X-Backstop-Priority | Header carrying per-request priority. | | baseRetryDelayMs | 250 | Base backoff; doubles each attempt. | | maxRetries | 3 | Retries before the circuit opens. | | circuitCooldownMs | 5000 | Cooldown before the breaker goes half-open. | | fallbackModel | — | Model to retry against once the circuit opens. | | fallbackBaseUrl | — | Optional base URL for the fallback model. | | estimateTokens | chars/4 | Custom token estimator. |

Status

This is a scaffold of the Python SDK's wrap() semantics. The Python package is the canonical, fully-tested implementation; this port tracks it for agentic / Node.js services. Distributed (Redis) budgets and OpenTelemetry export are Python-only today.

Scripts

npm run typecheck   # tsc --noEmit
npm run build       # emit dist/
npm test            # node --test (requires tsx)