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

ai-request-meter

v1.0.0

Published

Server-first AI usage, cost, latency, and quality logging SDK for OpenAI-compatible calls.

Readme

AI Request Meter

npm version npm downloads GitHub issues GitHub stars GitHub license

ai-request-meter is a server-first TypeScript SDK for tracking AI calls made through your application. It records token usage, estimated cost, latency, model, status, and local heuristic scores after each OpenAI-compatible response.

Current version: 1.0.0

NPM package: ai-request-meter

Repository: GitHub

Live demo and docs: Demo


Install

npm install ai-request-meter

pg is optional at package level. Install it only when you use postgresLogger():

npm install pg

Basic Usage

import { createAI, openaiProvider, postgresLogger } from 'ai-request-meter';

const ai = createAI({
  provider: openaiProvider({
    apiKey: process.env.OPENAI_API_KEY
  }),
  logger: postgresLogger({
    connectionString: process.env.DATABASE_URL
  })
});

const result = await ai.generate({
  taskName: 'customer_support_reply',
  model: 'gpt-4o-mini',
  messages: [
    { role: 'user', content: 'Write reply for this customer' }
  ]
});

console.log(result.usage, result.estimatedCost, result.scores);

Tracking works automatically when developers call AI through ai.generate(). It does not secretly intercept direct SDK calls made outside ai-request-meter.


PostgreSQL Migration

create table if not exists ai_request_meter_logs (
  id text primary key,
  task_name text not null,
  provider text not null,
  model text not null,
  input_tokens integer not null default 0,
  output_tokens integer not null default 0,
  total_tokens integer not null default 0,
  estimated_cost numeric not null default 0,
  latency_ms integer not null default 0,
  status text not null,
  error_message text,
  quality_score integer not null default 0,
  content_score integer not null default 0,
  readiness_score integer not null default 0,
  scores jsonb not null default '{}'::jsonb,
  metadata jsonb not null default '{}'::jsonb,
  prompt_text text,
  response_text text,
  created_at timestamptz not null
);

Privacy Defaults

By default, prompt and response text are opt-in. ai-request-meter stores metadata, token usage, estimated cost, model, provider, status, latency, and scores.

const ai = createAI({
  provider,
  logger,
  captureText: false
});

Use captureText: true only when your application policy allows prompt and response storage.


API

export {
  createAI,
  openaiProvider,
  postgresLogger,
  consoleLogger,
  noopLogger,
  estimateCost,
  scoreQuality,
  scoreContent,
  scoreReadiness
};
  • createAI(config) creates a tracked client.
  • ai.generate(options) runs one text chat-completion style request.
  • openaiProvider(options) supports OpenAI-compatible /chat/completions APIs.
  • postgresLogger(options) writes records into PostgreSQL.
  • consoleLogger() logs records locally while testing.
  • noopLogger() disables logging without changing call sites.
  • estimateCost() estimates token cost using built-in or custom model pricing.
  • scoreQuality(), scoreContent(), and scoreReadiness() run local deterministic heuristics.

The built-in gpt-4o-mini default pricing follows OpenAI's published token pricing at implementation time. For production billing accuracy, pass your own pricing map when your provider or contract differs.


Logger Error Behavior

Logging failures do not break AI responses by default.

const ai = createAI({
  provider,
  logger,
  failOnLoggerError: true
});

Use failOnLoggerError: true for strict pipelines where a missing log should fail the request.


Scope

v1 supports basic text chat-completion style calls through OpenAI-compatible APIs. Streaming, tool calls, embeddings, image inputs, MongoDB, SQLite, and hosted dashboards are planned as later additions.

📄 License

License: MIT