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

@seecost/tracker

v0.1.2

Published

Server-side SDK with a setup CLI for tracking LLM API usage costs

Readme

SeeCost Tracker

@seecost/tracker is a lightweight server-side SDK and setup CLI for tracking LLM API usage cost.

It intercepts fetch calls to OpenAI, Anthropic, and Gemini endpoints, reads usage metadata from JSON responses, estimates request cost from model pricing, and sends the result to a SeeCost ingest endpoint asynchronously.

Features

  • Tracks OpenAI, Anthropic, and Gemini requests made through fetch
  • Computes estimated USD cost from token usage
  • Sends cost logs to SeeCost without blocking the app response
  • Includes a small CLI to scaffold integration for Next.js, Express, Hono, and plain Node.js apps
  • Supports re-initialization so tracker settings can be refreshed safely
  • Can re-patch itself after globalThis.fetch has been replaced and initialized again

Installation

Install from npm:

npm install @seecost/tracker

Quick Start

Initialize the tracker once at the earliest server-side entry point in your app:

import { initSeeCostTrackerFromEnv } from "@seecost/tracker";

initSeeCostTrackerFromEnv();

Set the required environment variables:

SEECOST_INGEST_ENDPOINT=https://seecost.watch/api/tracker/ingest
SEECOST_API_KEY=sc_xxxxxxxxxxxxxxxxxxxx
SEECOST_DEBUG=false
SEECOST_APP_NAME=my-app

SEECOST_APP_NAME is optional, but recommended if you want logs grouped by application inside SeeCost.

What It Tracks

The tracker watches outgoing fetch requests to these providers:

  • OpenAI
  • Anthropic
  • Google Gemini

For supported JSON responses, it extracts usage metadata, normalizes the model name, calculates estimated cost, and optionally forwards a log to SeeCost.

Non-target requests pass through untouched.

How It Works

  1. The SDK monkey-patches globalThis.fetch
  2. Supported LLM API responses are cloned and parsed asynchronously
  3. Token usage is converted to USD cost using bundled pricing rules
  4. The app receives the original response immediately
  5. A background ingest request is sent to SeeCost if configured

If the ingest request fails, the SDK suppresses the error so your app request is not affected.

Manual Configuration

If you do not want to read from environment variables, initialize the tracker directly:

import { initSeeCostTracker } from "@seecost/tracker";

initSeeCostTracker({
  appName: process.env.SEECOST_APP_NAME,
  ingest: {
    endpoint: process.env.SEECOST_INGEST_ENDPOINT!,
    apiKey: process.env.SEECOST_API_KEY!,
  },
  debug: process.env.SEECOST_DEBUG === "true",
});

CLI Setup

The package also ships a seecost CLI for bootstrapping integration code.

Next.js

npx @seecost/tracker init nextjs

This will:

  • append SeeCost env vars to .env.local
  • create instrumentation.ts or src/instrumentation.ts
  • register initSeeCostTrackerFromEnv() in the Node.js runtime only

If the project already has an instrumentation file, run:

npx @seecost/tracker init nextjs --force

Express, Hono, and Node.js

npx @seecost/tracker init express
npx @seecost/tracker init hono
npx @seecost/tracker init node

This will:

  • append SeeCost env vars to .env
  • generate a bootstrap file
  • inject the bootstrap import at the top of an existing server entry file

Next.js Note for Linked Local Packages

If you install this package with a local file: dependency and the package source lives outside the Next.js project root, next dev with Turbopack may fail to resolve it even though npm ls shows it as installed.

Using the published npm package avoids that issue. If you must use a linked local dependency, configure Next.js so Turbopack can resolve the external package path.

Operational Notes

  • Use this on the server side only
  • Do not expose SEECOST_API_KEY to the browser
  • Initialize the tracker before your LLM client or any code that may replace fetch
  • Re-run initialization if your runtime swaps out globalThis.fetch or if you refresh ingest settings
  • Streaming responses are not tracked by the current implementation

Supported Runtime Behavior

  • Safe for repeated initialization
  • Reconfiguration updates ingest target and app name
  • Re-initialization can restore tracking after fetch has been replaced

API

initSeeCostTracker(options?)

Initializes the tracker with explicit options.

initSeeCostTrackerFromEnv(env?)

Reads tracker config from environment variables and initializes the tracker.

getSeeCostOptionsFromEnv(env?)

Parses environment variables and returns tracker options without initializing.

buildTrackerRuntimeConfig(options?)

Builds the pricing and alias lookup tables used at runtime.

Model Pricing and Aliases

Model pricing and alias mappings are bundled with the package:

Update those files if you need to add or adjust supported models.

Development

npm install
npm test

Build output is written to dist/.

License

MIT