How-to · Cost tracking

How to Track AI Costs Per User (And Why the OpenAI Total Lies to You)

Your OpenAI bill came in at $4,200 this month. Last month it was $3,100. The month before, $2,400.

That single number tells you almost nothing useful. If you run a SaaS that calls OpenAI or Anthropic per user action, you need to track AI costs per user. Not in aggregate, per user.

This guide walks you through why the total is misleading, how to calculate per-user cost manually, why the manual approach breaks the moment you grow, and how to automate the whole thing in two lines of code.

The total bill is a lie

A $4,200 bill doesn’t tell you which 7 users out of 800 are dragging your margin to zero. It doesn’t tell you that one of those 7 is on your $9 starter plan. And it definitely doesn’t tell you that a different user on your $99 business plan costs you $2.10 per month and is therefore your single best customer.

You stare at the total and feel uneasy. You can’t act on a single number.

Cost per user (14 users on the $9 plan)$0$15$30$45$9 plan revenue

The chart above shows 14 users, all on the same $9 plan. Some cost you $0.40 a month. Some cost you $42. Until you have this view, you are guessing about your margin.

Why the cost varies so wildly per user

Traditional SaaS charges variable revenue (per seat, per usage) and pays roughly fixed costs. Your AI feature flipped this. Revenue is flat (the subscription price), and cost is variable (whatever OpenAI charges based on tokens).

Power users hit your AI feature 50 to 100 times a day. Light users hit it twice a week. Same subscription price, vastly different costs.

This is the structural problem. You can’t fix it without measuring it.

How to calculate AI cost per user manually

OpenAI exposes the data you need, just not in a useful shape. Here is the manual path.

Step 1: Log every LLM call with the user ID

Every time your backend calls openai.chat.completions.create(), wrap it with a logger that captures the user, model, and token counts:

const response = await openai.chat.completions.create(params)

await db.aiCallLog.insert({
  userId: req.user.id,
  model: params.model,
  inputTokens: response.usage.prompt_tokens,
  outputTokens: response.usage.completion_tokens,
  timestamp: new Date(),
})

Step 2: Multiply tokens by the current price

Open the OpenAI pricing page and copy the per-million-token rate for each model you use. For gpt-4o today, $2.50 per million input tokens, $10 per million output tokens.

For each row, cost in USD is (inputTokens * inputPrice + outputTokens * outputPrice) / 1_000_000.

Step 3: Aggregate by user

Run a group-by:

SELECT user_id, SUM(cost_usd) AS total_cost
FROM ai_call_log
WHERE timestamp >= NOW() - INTERVAL '30 days'
GROUP BY user_id
ORDER BY total_cost DESC

The top of that list is where your margin is going.

Why manual tracking breaks the moment you grow

The query above looks fine. It works for a week.

Then OpenAI changes their pricing (they update it every few months). Your numbers go stale silently. You add Anthropic for one feature, then Gemini for another, and each provider has different token accounting rules.

Now you want margin per user, not just cost. So you join against subscriptions, normalize for partial months, handle plan changes. The query takes 30 seconds, you add indexes, you add materialized views. You spend a Friday afternoon debugging why a customer who upgraded mid-month shows the wrong revenue.

This is the point where most founders give up and just stare at the OpenAI total again.

Track AI costs per user with two lines of code

Wrap your OpenAI client in Weckr and the work above becomes automatic:

import { Weckr } from '@weckr/sdk'

const wk = new Weckr({
  apiKey: process.env.WECKR_API_KEY,
  plans: { free: 0, starter: 9, pro: 29, business: 99 }
})

const response = await wk.chat(openai, {
  model: 'gpt-4o-mini',
  messages: [{ role: 'user', content: prompt }],
  userId: user.id,
  feature: 'ai-summary',
  plan: user.plan,
})

Every call logs cost (calculated server side from current pricing, so it never goes stale), revenue (from the plan), and margin (revenue minus cost). The LLM response is identical to calling OpenAI directly, and the log fires asynchronously so you add zero latency.

You see the per-user breakdown live in the dashboard. Try it on seeded data without signing up at useweckr.com/demo.

A real example: the $9 plan costing $40

Imagine a customer named Alice. She is on your $9 starter plan, and she loves your AI summarization feature. She uses it 50 times a day, and every summary costs about $0.027 in gpt-4o tokens.

50 calls a day, 30 days a month, $0.027 each: $40.50 per month in API cost. You are charging her $9.

You are losing $31.50 a month on Alice.

Now multiply this. If 5 percent of your 800 users are Alices, you have 40 people losing you $31.50 a month, which is $1,260 in pure margin loss every month. The OpenAI total bill doesn’t tell you any of this.

With per-user tracking, you see Alice within hours. Then you have options: raise the price on her plan, set a spending cap so her usage downgrades to gpt-4o-mini when she hits $9 in API cost, or move her to a higher tier and pitch the upgrade. None of these are possible without knowing about Alice.

FAQ

How do I track AI costs per user in my SaaS app?

Use the Weckr SDK. Two lines of code wraps your existing OpenAI, Anthropic or Gemini client and logs cost and margin per user in real time. Install with npm install @weckr/sdk.

How do I calculate margin per user on LLM API calls?

Margin per user equals your subscription revenue from that user minus the total AI inference cost they generated that month. Weckr calculates this automatically from token counts and your configured plan prices.

What is the best way to monitor OpenAI costs per customer?

Wrap your OpenAI client with Weckr. It intercepts every call, calculates cost server-side from token usage, and logs it per userId. You see a dashboard showing which customers are profitable and which cost more than they pay.

How much does it cost to track LLM usage per user?

Weckr has a free tier that covers up to 50,000 requests per month. The Pro plan is $49 per month with unlimited requests. There are no per-request fees.

Can I track costs across multiple LLM providers in one dashboard?

Yes. Weckr supports OpenAI, Anthropic and Gemini in the same dashboard. All token counts are normalized so you can compare costs across providers.

Stop guessing about your AI margins

Stop staring at the OpenAI total. It tells you nothing about which customer to keep, which to upsell, and which to cap. Tracking per-user cost is step one; step two is reducing your OpenAI costs once you know where they come from.

You can build the per-user tracker yourself in about three weeks, or you can drop in Weckr and have it tonight. Try the live demo at useweckr.com/demo (no signup needed) and see the per-user view with real-looking data.

See the dashboard with real data, no signup needed.

Try the demo →