Skip to content

aiprofithub/aiprofithub-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AIProfitHub JavaScript SDK

Track AI model usage, token volume, customer attribution, feature attribution, and cost signals from JavaScript or TypeScript apps.

AI cost visibility for apps using OpenAI, Anthropic, Google, Mistral, Groq, LangChain, and custom LLM flows.

Get an AI Spend Audit · Create an account · Read the docs

Who this is for

This SDK is for builders who already have, or expect to have, real AI API usage inside a product.

Use it if you are building:

  • an AI SaaS product with usage-heavy features
  • a chatbot, copilot, support assistant, or agent workflow
  • a developer tool that calls LLM providers in the background
  • an internal AI app where finance still needs cost attribution
  • a product with fixed-price plans but variable AI usage
  • a team dashboard that needs cost by customer, feature, user, provider, or model

It is especially useful when the provider bill is visible, but the business question is still unanswered: which customer, feature, model, or workflow is quietly eating margin?

When this is useful

Situation Why it matters
Two customers pay the same plan but use very different token volume Customer-level margin can drift without showing up in provider dashboards.
AI features run through queues, workers, or agents Cost can hide outside the main request path.
Multiple providers or models are used Spend gets fragmented across billing dashboards.
Product teams ship new AI features quickly Feature-level tags make cost review possible later.
Finance asks for a spend report Usage events provide the raw attribution data.
You want budget alerts or routing decisions Clean event tags are the control-plane foundation.

Visual flow

flowchart LR
  A[Your app] --> B[AIProfitHub SDK]
  B --> C[Usage ingest]
  C --> D[AIProfitHub Cloud]
  D --> E[Cost dashboard]
  D --> F[Budget alerts]
  D --> G[Audit report]
  D --> H[Optimization recommendations]
Loading

What this SDK does

AIProfitHub helps teams see where AI spend is going before the bill becomes a surprise.

Use this SDK to send usage events from your app into AIProfitHub Cloud:

  • model used
  • input and output token counts
  • user, customer, and feature attribution
  • provider and cost metadata
  • usage data for dashboards, alerts, audits, and optimization

Install

npm install aiprofithub-sdk

Quick start

Import createClient from aiprofithub-sdk, then send usage events with provider, model, token counts, user, customer, and feature metadata.

Required fields:

  • provider
  • model
  • inputTokens
  • outputTokens

Example event:

import { createClient } from "aiprofithub-sdk";

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

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

More copy-paste examples: examples/copy-paste-recipes.md.

Start here

Goal Start with
Send one SDK event examples/basic-usage.ts
Copy practical snippets examples/copy-paste-recipes.md
Test API ingest without SDK install examples/rest-cookbook.md
Copy tracking into an app route examples/framework-integrations.md
Wrap existing OpenAI calls examples/openai-wrapper.md
Wrap Anthropic Claude calls examples/anthropic-wrapper.md
Track LangChain workflows examples/langchain-wrapper.md
Catch AI cost risk in pull requests toolkit/ai-cost-check-action/
Estimate monthly AI spend from the terminal toolkit/ai-cost-calculator-cli/
Generate a lightweight audit report from usage CSV toolkit/ai-spend-audit-report-generator.mjs

AI Cost Toolkit

Free tools and templates for builders who want AI cost visibility before they wire up a full dashboard.

Asset Use it when
toolkit/ai-cost-check-action/ You want a GitHub Action that flags AI cost risk in pull requests.
toolkit/ai-cost-calculator-cli/ You want a CLI-style monthly AI spend estimator.
toolkit/langchain-cost-callback.ts You use LangChain and want a starter cost attribution callback.
toolkit/nextjs-ai-usage-middleware.ts You use Next.js route handlers and want a reusable tracking wrapper.
toolkit/openai-cost-wrapper.ts You use the OpenAI SDK and want a drop-in attribution wrapper.
toolkit/ai-spend-audit-report-generator.mjs You want to generate a Markdown audit report from usage rows.
toolkit/customer-margin-risk-template.md You want to compare AI cost against customer revenue.
toolkit/llm-provider-router-template.md You want starter routing rules for cost, latency, and quality.
toolkit/budget-alert-policy-pack.yaml You want alert policies for spend, feature spikes, and margin risk.
toolkit/ai-cost-benchmark-dataset.csv You want sample data for testing dashboards and reports.

Toolkit assets by use case

1. Integrate usage tracking

Asset Use it when
examples/basic-usage.ts You want the smallest working SDK example.
examples/copy-paste-recipes.md You want copy-paste tracking snippets for common AI cost cases.
examples/rest-cookbook.md You want REST and cURL examples for non-JavaScript teams.
examples/framework-integrations.md You want a Next.js and Express route integration guide.
examples/nextjs-route-handler.ts You use Next.js App Router route handlers.
examples/express-route.ts You use Express or an Express-style Node API.
examples/openai-wrapper.ts You already use OpenAI chat completions.
examples/openai-wrapper.md You want the guide for wrapping OpenAI calls.
examples/anthropic-wrapper.ts You already use Anthropic Claude messages.
examples/anthropic-wrapper.md You want the guide for wrapping Claude calls.
examples/langchain-wrapper.ts You use LangChain-style chains or runnables.
examples/langchain-wrapper.md You want the guide for tracking LangChain workflows.

2. Estimate AI spend and margin risk

Asset Use it when
examples/cost-calculator.html You want a browser-based AI spend and margin risk calculator.
examples/cost-calculator.md You want the decision guide for using the calculator.
examples/customer-margin-risk-template.md You want to compare AI cost per customer against customer revenue.
toolkit/ai-cost-calculator-cli/ai-cost-calculator.mjs You want a terminal-based estimator.
toolkit/customer-margin-risk-template.md You want a customer margin table template.

3. Control budgets, alerts, and routing

Asset Use it when
examples/provider-router-decision-guide.md You want to choose provider/model routes by cost, risk, and margin.
examples/budget-alert-policy-template.md You want budget thresholds, anomaly alerts, and route guardrails.
examples/github-action-ai-cost-check.md You want a CI reminder when pull requests add AI cost risk.
toolkit/ai-cost-check-action/ You want an action-style PR risk scanner.
toolkit/budget-alert-policy-pack.yaml You want reusable starter alert policies.
toolkit/llm-provider-router-template.md You want a model-routing decision table.

4. Evaluate AIProfitHub before buying

Asset Use it when
examples/sample-ai-spend-audit-report.md You want to see what a paid AI Spend Audit can return.
examples/agent-playbooks.md You want sample outputs from the 9 AIProfitHub product agents.
examples/README.md You want the full decision path from free tracking to paid Cloud.
toolkit/ai-spend-audit-report-generator.mjs You want to generate a local audit report from CSV.
toolkit/ai-cost-benchmark-dataset.csv You want sample rows to test the report generator.

Required fields

Field Required Why it matters
provider Yes Groups spend by AI provider.
model Yes Shows which models create cost.
inputTokens Yes Measures prompt volume.
outputTokens Yes Measures generated output volume.
userId No Attributes usage to an app user.
customerId No Attributes usage to a paying customer.
feature No Shows which product feature drives spend.
costUsd No Lets you pass known cost estimates.
metadata No Adds extra trace context for audits.

Decision guide

You need to... Use this SDK? Next action
Track AI calls from a JavaScript app Yes Install the SDK and send track events.
Wrap OpenAI chat completions Yes Use examples/openai-wrapper.md.
Wrap Anthropic Claude messages Yes Use examples/anthropic-wrapper.md.
Track LangChain workflows Yes Use examples/langchain-wrapper.md.
Choose model/provider routes Yes Use examples/provider-router-decision-guide.md.
Define AI budget alert policy Yes Use examples/budget-alert-policy-template.md.
Check customer margin risk Yes Use examples/customer-margin-risk-template.md.
Copy tracking into a Next.js or Express route Yes Use examples/framework-integrations.md.
Test API ingest without the SDK Yes Use examples/rest-cookbook.md.
Add a PR reminder for AI cost risk Yes Use examples/github-action-ai-cost-check.md or toolkit/ai-cost-check-action/.
Estimate monthly AI spend before connecting data Yes Open examples/cost-calculator.html or run toolkit/ai-cost-calculator-cli/ai-cost-calculator.mjs.
See what an audit report looks like before buying Yes Read examples/sample-ai-spend-audit-report.md.
Generate an audit report from sample usage CSV Yes Use toolkit/ai-spend-audit-report-generator.mjs.
See sample agent outputs before buying Yes Read examples/agent-playbooks.md.
Find which customer or feature burns the most AI budget Yes Send customerId and feature with each event.
Get a one-time cost leak report Yes Start with an AI Spend Audit.
Replace your generic log stack No Use AIProfitHub for AI cost intelligence, not generic logs.
Open source your private SaaS backend No Keep backend, billing, and dashboard code private.

Community questions

If you are working through AI cost tracking, open an issue using one of the templates:

  • SDK integration help: ask where to place tracking in a framework, route, worker, or provider wrapper.
  • AI margin question: ask how to think about customer margin, feature profitability, plan limits, or usage guardrails.
  • AI cost tracking question: ask about provider/model tags, feature attribution, budget alerts, or audit report structure.

Good questions to ask:

  • How should I tag AI requests so finance can understand the bill?
  • How do I know which customer or feature is burning margin?
  • Should I track cost in the app, gateway, queue worker, or provider wrapper?
  • What budget alerts should I add before usage scales?
  • Which model/provider routing rules should I test first?

Discussion starter

Want to compare notes with other builders? Start with this question:

How are you tracking AI API spend today: provider dashboard, spreadsheet, internal dashboard, logs, billing export, or a dedicated tool?

If GitHub Discussions is enabled for this repository, pin this as the first discussion topic: How do you track AI API spend today?

Safety notes

Do not commit credentials, environment files, backend source, billing logic, customer data, raw prompts, provider API keys, or private dashboard code into public repositories.

Commercial path

License

MIT

About

JavaScript SDK for tracking AI API usage, cost, model spend, and feature-level attribution with AIProfitHub.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors