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

@llmetrics/sdk

v0.1.3

Published

Official JavaScript/TypeScript SDK for LLMetrics — LLM cost & performance tracking

Readme

@llmetrics/sdk

Official JavaScript / TypeScript SDK for LLMetrics — lightweight LLM cost and performance tracking.

Installation

npm install @llmetrics/sdk
# or
yarn add @llmetrics/sdk
# or
pnpm add @llmetrics/sdk

Quick start

import { llmetrics } from '@llmetrics/sdk';

llmetrics.init({
  apiKey: process.env.LLMETRICS_API_KEY!,
});

// After any LLM call — fire and forget, batched automatically
const response = await openai.chat.completions.create({ ... });

llmetrics.track({
  feature: 'lesson-generation',
  provider: 'openai',
  model: 'gpt-4o-mini',
  inputTokens: response.usage.prompt_tokens,
  outputTokens: response.usage.completion_tokens,
});

Init options

| Option | Type | Default | Description | |---|---|---|---| | apiKey | string | — | Your LLMetrics API key (from the API Keys page in your dashboard) | | flushIntervalMs | number | 1500 | How often the event queue flushes | | maxQueueSize | number | 50 | Max events to buffer before forcing a flush | | timeoutMs | number | 2000 | Request timeout for each flush | | debug | boolean | false | Log flush errors to console |

Tracking events

llmetrics.track(event) — fire and forget

Adds the event to an internal queue that flushes automatically. Never throws. Ideal for production use.

llmetrics.track({
  feature: 'chat',          // your feature name — groups events in the dashboard
  provider: 'openai',       // 'openai' | 'anthropic'
  model: 'gpt-4o-mini',
  inputTokens: 512,
  outputTokens: 128,
  userId: 'user_abc123',    // optional — track per-user costs
  meta: { promptVersion: 2 }, // optional — any extra data
});

llmetrics.trackAsync(event) — awaitable

Sends immediately without queuing. Throws on failure. Useful in serverless functions that may not stay alive long enough for the queue to flush.

await llmetrics.trackAsync({
  feature: 'summarize',
  provider: 'anthropic',
  model: 'claude-haiku-4-5',
  inputTokens: response.usage.input_tokens,
  outputTokens: response.usage.output_tokens,
});

llmetrics.flush() — manual flush

Force the queue to send immediately. Call this before your process exits.

await llmetrics.flush();

Event fields

| Field | Type | Required | Description | |---|---|---|---| | feature | string | ✓ | Logical feature name (e.g. "chat", "summarize") | | provider | string | ✓ | LLM provider: "openai" or "anthropic" | | model | string | ✓ | Model ID (e.g. "gpt-4o-mini", "claude-haiku-4-5") | | inputTokens | number | ✓ | Prompt token count | | outputTokens | number | ✓ | Completion token count | | userId | string | — | Your app's user identifier | | ts | number | — | Unix timestamp in ms (defaults to Date.now()) | | meta | object | — | Any extra metadata to store with the event |

Examples

OpenAI

import OpenAI from 'openai';
import { llmetrics } from '@llmetrics/sdk';

const openai = new OpenAI();

const response = await openai.chat.completions.create({
  model: 'gpt-4o-mini',
  messages: [{ role: 'user', content: prompt }],
});

llmetrics.track({
  feature: 'chat',
  provider: 'openai',
  model: response.model,
  inputTokens: response.usage.prompt_tokens,
  outputTokens: response.usage.completion_tokens,
  userId: session.userId,
});

Anthropic

import Anthropic from '@anthropic-ai/sdk';
import { llmetrics } from '@llmetrics/sdk';

const anthropic = new Anthropic();

const response = await anthropic.messages.create({
  model: 'claude-haiku-4-5',
  max_tokens: 1024,
  messages: [{ role: 'user', content: prompt }],
});

llmetrics.track({
  feature: 'summarize',
  provider: 'anthropic',
  model: response.model,
  inputTokens: response.usage.input_tokens,
  outputTokens: response.usage.output_tokens,
});

License

MIT