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

llmargus

v0.1.2

Published

> Track LLM costs per user, per feature — in one line of code.

Readme

llmargus

Track LLM costs per user, per feature — in one line of code.

GitHub Stars GitHub Forks Last commit Contributors Open issues Release License

npm Version npm Weekly Downloads npm Total Downloads npm Types npm Node

Language · TypeScript AI SDK · OpenAI AI SDK · Anthropic AI SDK Dual package ESM+CJS

llmargus wraps your OpenAI or Anthropic client and silently tracks every call — tokens in, tokens out, latency, streaming or not — then ships the data to your LLMargus dashboard fire-and-forget with zero added latency.


Install

npm install llmargus
# or
pnpm add llmargus
# or
yarn add llmargus

Quickstart

OpenAI

import OpenAI from "openai"
import llmargus from "llmargus"

llmargus.init({ apiKey: "lmg_..." })

const openai = llmargus.wrap(new OpenAI())

// Use exactly like you normally would
const response = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Hello!" }],
})

Anthropic

import Anthropic from "@anthropic-ai/sdk"
import llmargus from "llmargus"

llmargus.init({ apiKey: "lmg_..." })

const anthropic = llmargus.wrap(new Anthropic())

const response = await anthropic.messages.create({
  model: "claude-opus-4-5",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello!" }],
})

Attribution — tag by user & feature

Option 1: withContext (recommended for request handlers)

Wraps a block of async code and automatically tags every LLM call inside it.

await llmargus.withContext({ userId: "user_123", feature: "summarizer" }, async () => {
  await openai.chat.completions.create({ ... })
  // automatically tagged with userId + feature
})

Option 2: wrap-time defaults

const openai = llmargus.wrap(new OpenAI(), { feature: "chat" })

Option 3: manual track()

For providers the SDK does not support yet, or raw fetch calls:

llmargus.track({
  provider: "openai",
  model: "gpt-4o",
  tokensIn: 500,
  tokensOut: 120,
  latencyMs: 800,
  stream: false,
  success: true,
  ts: Date.now(),
})

Streaming

Works out of the box — no changes needed:

const stream = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Tell me a story" }],
  stream: true,
})

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "")
}
// event is enqueued once the stream ends — includes ttftMs

API Reference

llmargus.init(config)

| Option | Type | Default | Description | |---|---|---|---| | apiKey | string | required | Your LLMargus API key | | ingestUrl | string | https://llmargus-web.vercel.app/api/ingest | Custom ingest endpoint | | flushIntervalMs | number | 2000 | How often to flush the event queue (ms) | | maxBatchSize | number | 50 | Max events per batch before early flush |

llmargus.wrap(client, defaults?)

Returns a proxied version of the client. Accepts an optional { userId, feature } default context.

llmargus.withContext(ctx, fn)

Runs fn with ctx available to all wrapped calls inside it. Uses AsyncLocalStorage — works across awaits.

llmargus.track(event)

Manually enqueue a CostEvent. Useful for unsupported providers.


How it works

  • Wraps your client using JavaScript's Proxy API — the original client is never mutated
  • Events are buffered in memory and flushed in batches every 2 seconds (configurable)
  • Flush also triggers on process.beforeExit to prevent event loss in serverless environments
  • Failures are swallowed silently — LLMargus never throws into your application

Contributing

See CONTRIBUTING.md.

License

This SDK is licensed under the Elastic License 2.0.

Permitted:

  • Use in your own applications and businesses, including commercial products
  • Modification and contribution back to this repository

Not permitted:

  • Offering this software to third parties as a hosted or managed service
  • Building and selling a competing LLM cost-tracking platform using this code
  • Removing or obscuring copyright notices