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

@llmcosttracker/sdk

v0.4.1

Published

Drop-in cost tracking for Anthropic, OpenAI, Google Gemini, and xAI Grok calls

Readme

@llmcosttracker/sdk

Drop-in cost tracking for Anthropic, OpenAI, Google Gemini, and xAI Grok calls.

Install

npm install @llmcosttracker/sdk

Usage

import { trackedCall } from '@llmcosttracker/sdk'

const response = await trackedCall({
  client: anthropic,
  feature: 'search',
  userId: session.userId,
  apiKey: process.env.LLMCOSTTRACKER_API_KEY,
  params: {
    model: 'claude-sonnet-4-6',
    messages,
    max_tokens: 1024,
  }
})

Streaming

import { trackedStream } from '@llmcosttracker/sdk'

const stream = await trackedStream({
  client: anthropic,
  feature: 'chat',
  userId: session.userId,
  apiKey: process.env.LLMCOSTTRACKER_API_KEY,
  params: {
    model: 'claude-sonnet-4-6',
    messages,
    max_tokens: 1024,
  }
})

Budget Enforcement

Set a per-user spend limit and the SDK will enforce it automatically. Configure once at the call site — no changes to your existing params or response handling.

import { trackedCall, LLMBudgetExceededError } from '@llmcosttracker/sdk'

try {
  const response = await trackedCall({
    client: anthropic,
    feature: 'search',
    userId: session.userId,
    apiKey: process.env.LLMCOSTTRACKER_API_KEY,
    params: {
      model: 'claude-sonnet-4-6',
      messages,
      max_tokens: 1024,
    },
    budget: {
      userId: session.userId,
      limitUsd: 10,
      windowType: 'month',
      action: 'block',
      alertThresholdPct: 80,
    },
    onBudgetWarning: (result) => {
      console.warn(`User ${result.budgetConfig.userId} is at ${result.spendUsd.toFixed(4)} of $${result.limitUsd} limit`)
    },
  })
} catch (err) {
  if (err instanceof LLMBudgetExceededError) {
    // Handle gracefully — return a friendly message to your user
    console.error(`Budget exceeded: $${err.spendUsd.toFixed(4)} of $${err.limitUsd} ${err.windowType} limit`)
  }
}

Budget options

| Option | Type | Required | Description | |--------|------|----------|-------------| | userId | string | Yes | Must match the userId on the call | | limitUsd | number | Yes | Spend cap in USD | | windowType | 'day' \| 'week' \| 'month' | Yes | Rolling window for the limit | | action | 'block' \| 'warn' \| 'dry_run' | Yes | What happens when the limit is reached | | alertThresholdPct | number | No | Fire onBudgetWarning at this % of limit (default: 80) |

Actions

| Action | Behavior | |--------|----------| | block | Throws LLMBudgetExceededError — call does not proceed | | warn | Call proceeds, onBudgetWarning fires | | dry_run | Call proceeds, logs a console warning — safe for testing |

Budget enforcement requires a Growth plan on llmcosttracker.com.

Options

| Option | Type | Required | Description | |--------|------|----------|-------------| | client | Anthropic \| OpenAI \| GoogleGenerativeAI | Yes | Your initialized client | | params | object | Yes | Params passed to the underlying call | | apiKey | string | Yes | Your LLM Cost Tracker project API key | | feature | string | No | Tag for this call e.g. 'search' | | userId | string | No | Your app's user identifier | | promptVersion | string | No | Tag deploys for cost comparison e.g. process.env.DEPLOY_SHA | | budget | BudgetConfig | No | Per-user spend limit configuration | | onBudgetWarning | (result: BudgetCheckResult) => void | No | Callback fired at alert threshold or on warn action | | endpoint | string | No | Custom endpoint for self-hosted installs |

Links