I built a free JavaScript SDK to track AI API usage and cost

Dev.to / 5/17/2026

📰 NewsDeveloper Stack & InfrastructureSignals & Early TrendsTools & Practical Usage

Key Points

  • The post includes installation and a basic example showing how to call trackUsage with provider, model, token counts, and cost fields.

I’ve been building AIProfitHub, a tool for tracking AI API usage and cost across AI products.

One problem I kept seeing: teams ship AI features fast, but they often don’t know which feature, customer, user, or model is creating the cost.

So I published a small JavaScript SDK to make usage tracking easier.

What it does

  • Track AI usage events
  • Attribute cost by user, team, feature, customer, and model
  • Prepare data for budget alerts and cost analysis
  • Works with OpenAI, Anthropic, and LangChain-style wrappers

Install

npm install aiprofithub-sdk

Basic example

import { createClient } from "aiprofithub-sdk";

const client = createClient({
  apiKey: process.env.AIPROFITHUB_API_KEY,
});

await client.trackUsage({
  provider: "openai",
  model: "gpt-4o-mini",
  feature: "support-chat",
  userId: "user_123",
  inputTokens: 1200,
  outputTokens: 350,
  costUsd: 0.0042,
});

Links

GitHub:

https://github.com/aiprofithub/aiprofithub-js

NPM:

https://www.npmjs.com/package/aiprofithub-sdk

I’d love feedback from developers building AI products:

How are you currently tracking LLM usage, token spend, and cost per feature?