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

agentbill

v0.1.1

Published

Usage-based billing for AI agents — 3-line integration with pre-flight budget guardrails

Downloads

43

Readme

agentbill

Usage-based billing for AI agents — preflight budget guardrails in 3 lines.

npm install agentbill

Quick start

import { AgentBill } from 'agentbill'

const bill = new AgentBill({ apiKey: process.env.AGENTBILL_API_KEY })

// Before running the agent — check if the customer has budget
const check = await bill.preflight({ customerId: 'user_123', agentId: 'research', estimatedUnits: 10 })
if (!check.approved) {
  throw new Error('Budget exceeded')
}

// After the agent finishes — record what was used
await bill.record({ customerId: 'user_123', agentId: 'research', units: 8 })

Why AgentBill?

Monthly caps let agents burn through a budget in hours. AgentBill adds a preflight check — the agent asks permission before it runs, not after it's already spent the money.

  • Preflight blocks the run before it starts if the customer is over budget
  • Per-request ceiling: block any single run that would cost too much
  • Idempotent recording: safe to call from retried or parallel workflows
  • Free tier: 1,000 units/customer, no credit card required

API

new AgentBill({ apiKey })

Get your API key at agentbill.fly.dev/register.

bill.preflight(options)

Check if a customer has budget before starting work.

| Option | Type | Default | Description | |--------|------|---------|-------------| | customerId | string | "default" | Your internal customer ID | | agentId | string | required | Agent or task type identifier | | estimatedUnits | number | 1 | Expected units for this run | | ceiling | number | — | Block run if estimatedUnits exceeds this |

Returns { approved: boolean, remainingUnits: number \| null }.

bill.record(options)

Record a billable event after work completes.

| Option | Type | Default | Description | |--------|------|---------|-------------| | customerId | string | "default" | Your internal customer ID | | agentId | string | required | Agent or task type identifier | | units | number | 1 | Units consumed | | metadata | object | — | Key-value pairs stored with the event |

Returns { recorded: boolean, eventId: string, remainingUnits: number \| null }.

LangChain integration

import { AgentBill } from 'agentbill'
import { ChatAnthropic } from '@langchain/anthropic'
import { createReactAgent } from '@langchain/langgraph/prebuilt'

const bill = new AgentBill({ apiKey: process.env.AGENTBILL_API_KEY })

async function runAgent(customerId: string, input: string) {
  const check = await bill.preflight({ customerId, agentId: 'assistant', estimatedUnits: 5 })
  if (!check.approved) throw new Error(`Blocked: ${check.remainingUnits} units remaining`)

  const agent = createReactAgent({ llm: new ChatAnthropic({ model: 'claude-3-5-haiku-latest' }), tools: [] })
  const result = await agent.invoke({ messages: [{ role: 'user', content: input }] })

  await bill.record({ customerId, agentId: 'assistant', units: 5 })
  return result
}

Links