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

@alicantorun/aimetrics-sdk

v1.0.0

Published

SDK for AiMetrics - LLM Observability and Analytics

Readme

AiMetrics SDK

A comprehensive SDK for tracking and analyzing LLM/AI system metrics and performance.

Installation

npm install @aimetrics/sdk

If you're using OpenAI (which is a peer dependency):

npm install @aimetrics/sdk openai

Quick Start

import { AiMetricsTracker } from "@aimetrics/sdk";
import OpenAI from "openai";

// Initialize the metrics tracker
const metrics = new AiMetricsTracker({
    apiKey: "your-metrics-api-key", // Get this from AiMetrics dashboard
    clientId: "your-client-id", // Your unique identifier
    endpoint: "https://api.aimetrics.ai", // Optional: defaults to localhost:3001
    batchSize: 10, // Optional: batch size for sending metrics
    flushInterval: 5000, // Optional: flush interval in ms
    debug: true, // Optional: enable debug logging
});

// Initialize your LLM client
const openai = new OpenAI({
    apiKey: process.env.OPENAI_API_KEY,
});

// Track LLM calls
async function chatCompletion(messages) {
    return await metrics.track(
        {
            model: "gpt-3.5-turbo",
            messages,
        },
        async () => {
            const response = await openai.chat.completions.create({
                model: "gpt-3.5-turbo",
                messages,
            });
            return response;
        }
    );
}

// Example usage
async function main() {
    try {
        const response = await chatCompletion([
            { role: "system", content: "You are a helpful assistant." },
            { role: "user", content: "Hello, how are you?" },
        ]);
        console.log(response.choices[0].message);
    } catch (error) {
        console.error("Error:", error);
    }
}

// Get metrics
async function getMetrics() {
    const startDate = new Date(Date.now() - 24 * 60 * 60 * 1000); // Last 24 hours
    const metrics = await metrics.getMetrics(startDate);
    console.log("Metrics:", metrics);
}

// Clean up when done
function cleanup() {
    metrics.destroy();
}

Features

  • Real-time metrics tracking
  • Token usage monitoring
  • Cost calculation
  • Response quality analysis
  • Performance metrics
  • Content analysis
  • Batch processing
  • Error tracking

Configuration

The SDK accepts the following configuration options:

| Option | Type | Required | Default | Description | | ------------- | ------- | -------- | ------------------------- | ----------------------------------------- | | apiKey | string | Yes | - | Your AiMetrics API key | | clientId | string | Yes | - | Your unique client identifier | | endpoint | string | No | http://localhost:3001/api | Custom metrics server endpoint | | batchSize | number | No | 10 | Number of metrics to batch before sending | | flushInterval | number | No | 5000 | Interval in ms to flush metrics | | debug | boolean | No | false | Enable debug logging |

Metrics Tracked

Basic Metrics

  • Total calls
  • Success/failure rate
  • Response times
  • Token usage
  • Costs

Quality Metrics

  • Response coherence
  • Relevance scores
  • Toxicity detection
  • Content analysis

Performance Metrics

  • Time to first token
  • Tokens per second
  • Retry counts
  • Error rates

Content Analysis

  • Word count
  • Code snippet detection
  • Programming languages used
  • Sentiment analysis
  • Average word length

Error Handling

The SDK includes comprehensive error handling:

try {
    const response = await metrics.track(
        {
            model: "gpt-3.5-turbo",
            messages: [{ role: "user", content: "Hello" }],
        },
        async () => {
            // Your LLM call here
        }
    );
} catch (error) {
    if (error.response) {
        console.error("API Error:", error.response.data);
    } else {
        console.error("Error:", error.message);
    }
}

Best Practices

  1. Initialize the tracker once and reuse the instance
  2. Use appropriate batch sizes for your use case
  3. Call destroy() when shutting down your application
  4. Enable debug mode during development
  5. Handle errors appropriately
  6. Use environment variables for sensitive data

Support

For issues and feature requests, please visit our GitHub repository.

License

MIT License