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

agentmetrics

v0.2.0

Published

Monitor your AI agents. Track cost, latency, and errors in two lines of code.

Readme

agentmetrics - JavaScript / TypeScript SDK

npm Node 18+ License: MIT

AgentMetrics JavaScript/TypeScript SDK. Wrap any async agent function with agentmetrics.track() and every run reports back to your dashboard showing latency, cost, token usage, tool calls, and failures, self-hosted with no account required.


Install

npm install agentmetrics

Requires Node.js 18 or later. Works with TypeScript, ESM, and CommonJS.


Quickstart

import agentmetrics from "agentmetrics";

agentmetrics.configure({ baseUrl: "http://localhost:8099" });
agentmetrics.instrument(); // auto-patches OpenAI and Anthropic

const run = agentmetrics.track("my-agent", async (task: string) => {
  const answer = await callLlm(task);
  return answer;
});

const result = await run("summarize this document");

API

agentmetrics.configure()

Call once at startup before any track() wrappers execute.

agentmetrics.configure({
  baseUrl: "http://localhost:8099",  // AgentMetrics server address
  sampleRate: 1.0,                   // optional, 0.0 to 1.0
});

agentmetrics.instrument()

Patches installed LLM SDKs to auto-capture token counts and model names on every call, and is safe to call multiple times.

agentmetrics.instrument();

Supported: OpenAI (+ Azure, Groq, Together AI) · Anthropic

agentmetrics.track()

Wraps an async agent function. Returns a new function with identical signature.

const run = agentmetrics.track("my-agent", async (task: string) => {
  return await callLlm(task);
});

// With metadata
const run = agentmetrics.track(
  { agentId: "my-agent", metadata: { env: "production" } },
  async (task: string) => callLlm(task)
);

Signature

agentmetrics.track(
  agentId: string | TrackOptions,
  fn: (...args: unknown[]) => Promise<unknown>
): (...args: Parameters<fn>) => Promise<ReturnType<fn>>

agentmetrics.step()

Times a named phase within a tracked agent.

const run = agentmetrics.track("pipeline", async (query: string) => {
  const docs = await agentmetrics.step("retrieve", () => vectorSearch(query));
  const answer = await agentmetrics.step("generate", () => callLlm(query, docs));
  return answer;
});

agentmetrics.tool()

Tracks an individual tool call within a tracked agent.

const run = agentmetrics.track("research-agent", async (query: string) => {
  const results = await agentmetrics.tool("web_search", () => webSearch(query));
  return summarize(results);
});

agentmetrics.score()

Attaches a named evaluation score to the current run. Call from inside a track() wrapper.

const run = agentmetrics.track("my-agent", async (task: string) => {
  const answer = await callLlm(task);
  agentmetrics.score("relevance", 0.92);
  return answer;
});

agentmetrics.flush()

Drains all buffered events. Call before process.exit() in scripts.

await agentmetrics.flush();

agentmetrics.traceId

Returns the active trace ID from inside a tracked function.

const run = agentmetrics.track("my-agent", async (task: string) => {
  console.log(agentmetrics.traceId); // "a3f1c2d4-..."
  return await callLlm(task);
});

TypeScript

Full TypeScript types are bundled with the package.

import agentmetrics, { type TrackOptions, type AgentMetricsOptions } from "agentmetrics";

CommonJS

const agentmetrics = require("agentmetrics");

agentmetrics.configure({ baseUrl: "http://localhost:8099" });
agentmetrics.instrument();

const run = agentmetrics.track("my-agent", async (task) => callLlm(task));

License

MIT