
Research
Supply Chain Attack on Axios Pulls Malicious Dependency from npm
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.
ai-cost-tracker
Advanced tools
ai-cost-tracker is a production-ready TypeScript/Node.js library for tracking LLM API token usage and USD costs per user and feature.
LLM usage costs are easy to lose track of when your application only monitors provider-level totals.
Typical pain points:
Wrap your OpenAI/Anthropic calls with trackCosts(...). The library extracts usage metadata, computes cost from model pricing, and writes logs to a fast SQLite backend (better-sqlite3).
npm install ai-cost-tracker better-sqlite3
Optional peer SDKs:
npm install openai @anthropic-ai/sdk
import OpenAI from 'openai';
import { initTracker, trackCosts } from 'ai-cost-tracker';
const storage = initTracker({ storagePath: 'costs.db', orgId: 'acme-inc' });
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
async function chat(prompt: string) {
return trackCosts(
async () => {
return openai.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: prompt }],
});
},
{ userId: 'user_123', feature: 'chat' }
);
}
await chat('Hello!');
console.log(storage.getTotalCost());
console.log(storage.getTopUsers(10));
console.log(storage.getTopFeatures(10));
usage.prompt_tokens, usage.completion_tokens)usage.input_tokens, usage.output_tokens)initTracker(options)Initializes global tracker state and returns a SQLiteStorage instance.
initTracker({ storagePath: string, orgId?: string }): SQLiteStorage
trackCosts(fn, options)Wraps an async/promise-producing function, measures latency, extracts token usage, computes cost, and logs usage.
trackCosts<T>(fn: () => Promise<T> | T, options: TrackOptions): Promise<T>
TrackOptions:
userId: stringfeature: stringmetadata?: Record<string, unknown>orgId?: stringtrackManual(input)Manually logs usage when no provider response is available.
trackManual({
userId,
feature,
model,
tokensIn,
tokensOut,
latencyMs?,
metadata?,
orgId?,
timestamp?
}): CostLog
calculateCost(model, tokensIn, tokensOut)Computes USD cost using built-in pricing table and partial model matching.
getModelPricing(model)Returns { input, output } rates in USD per 1M tokens.
SQLiteStorageinitDb(): voidlog(costLog: CostLog): voidgetTotalCost(filters?: FilterOptions): numbergetTopUsers(limit?: number): Array<{ userId, cost, count }>getTopFeatures(limit?: number): Array<{ feature, cost, count }>close(): voidFilterOptions:
userId?: stringfeature?: stringorgId?: stringmodel?: stringstartTime?: Date | stringendTime?: Date | stringYes. Package exports support both require('ai-cost-tracker') and import { ... } from 'ai-cost-tracker'.
The tracked function result is still returned. Logging failures are caught to avoid breaking request handling.
Yes. Pass any writable path via initTracker({ storagePath: 'path/to/file.db' }).
/examples/example-openai.ts/examples/example-anthropic.ts/examples/example-express.tsnpm install
npm run build
npm test
npm run lint
FAQs
Track LLM API token usage and USD cost per user and feature.
The npm package ai-cost-tracker receives a total of 1 weekly downloads. As such, ai-cost-tracker popularity was classified as not popular.
We found that ai-cost-tracker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.

Security News
TeamPCP is partnering with ransomware group Vect to turn open source supply chain attacks on tools like Trivy and LiteLLM into large-scale ransomware operations.