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

@reactive-agents/cost

v0.10.6

Published

Cost management for Reactive Agents — complexity routing and budget enforcement

Readme

@reactive-agents/cost

Cost management for the Reactive Agents framework. v0.10.3

Routes tasks to the cheapest capable model using a 27-signal complexity router, caches semantically-similar requests, enforces budgets at four levels (per-request / per-session / daily / monthly), and tracks token + USD spend in real time. Pricing can be loaded from a static table or fetched dynamically (OpenRouter and provider APIs supported).

Installation

bun add @reactive-agents/cost

Or via the umbrella:

bun add reactive-agents

Features

  • Complexity router — 27 signals (length, code presence, multi-step phrasing, entity count, etc.) classify each task and select Haiku / Sonnet / Opus or local equivalents
  • Semantic cache — embedding-similarity lookup of prior responses, with cache-aware token discounts when the provider supports prompt caching
  • Budget enforcer — blocks a request before it spends if any of the four budget windows would be exceeded; emits BudgetExceededError
  • Cost tracker — accumulates token + USD spend per agent / session / day / month, persisted via BudgetDb (SQLite)
  • Dynamic pricing.withDynamicPricing() on the builder fetches up-to-date model prices including OpenRouter; falls back to static table on failure
  • Prompt compressor — optional compression layer for context-heavy requests

Quick Example

import { ReactiveAgents } from "reactive-agents";

const agent = await ReactiveAgents.create()
  .withName("budget-agent")
  .withProvider("anthropic")
  .withDynamicPricing()
  .withCostTracking({
    perRequest: 0.10,    // USD
    perSession: 1.00,
    daily: 5.00,
    monthly: 50.00,
  })
  .build();

const result = await agent.run("Summarize this 200-word document");
console.log(result.metadata.cost);      // { usd: 0.0003, tokens: 450 }
console.log(result.metadata.modelUsed); // "claude-haiku-4-5-20251001" — auto-routed
console.log(result.metadata.cacheHit);  // true | false

Routing Logic

| Task signals (sample) | → Selected tier | | -------------------------------------- | -------------------- | | Short, factual, single-turn | Haiku (cheapest) | | Code analysis, multi-step, structured | Sonnet | | Complex reasoning, research, long-form | Opus |

The router uses heuristic classification by default; analyzeComplexity() exposes the full signal vector for callers who want LLM-assisted routing.

Direct API

import {
  analyzeComplexity,
  routeToModel,
  estimateCost,
  makeBudgetEnforcer,
  makeSemanticCache,
} from "@reactive-agents/cost";

const analysis = analyzeComplexity({
  input: "Write a binary search tree in Rust",
});
const model = routeToModel(analysis, { provider: "anthropic" });

const cost = estimateCost({
  model,
  inputTokens: 500,
  outputTokens: 1200,
});

Budget Levels

| Level | Window | Persisted to | | ------------- | ---------------- | ------------ | | perRequest | single LLM call | in-memory | | perSession | one agent run | in-memory | | daily | UTC day rollover | SQLite | | monthly | calendar month | SQLite |

Each level can be omitted; only configured limits are enforced.

Key Exports

| Export | Purpose | | --------------------------------- | -------------------------------------------------- | | CostService, CostServiceLive | Composite cost-management entry point | | analyzeComplexity, routeToModel | 27-signal complexity router | | makeSemanticCache | Embedding-similarity response cache | | makeBudgetEnforcer, makeBudgetDb | 4-level budget enforcement + SQLite persistence | | makeCostTracker | Token + USD accumulator | | makePromptCompressor | Context compression | | estimateCost, estimateTokens | Pricing helpers | | createCostLayer | Factory for the runtime layer | | BudgetExceededError, RoutingError | Tagged errors |

Documentation

License

MIT