Attribute AI cost to users and features

If your AI bill is one mysterious number, you need to break it down. Cost attribution turns single number bills into detailed, feature-by-feature breakdowns.

PostHog already computes $ai_total_cost_usd on every generation, cache reads included. All it needs from you is dimensions to split by.

Add properties

You can take advantage of PostHog's properties to make sense of your AI bill:

  • Use a custom property to name specific features
  • Default properties like $ai_model and $ai_provider are included automatically
  • distinct_id tells you which customers your spend goes to

Once you've added properties, your AI bill is no longer one line: Fig. 1 – three surfaces on the same account, two of them steady, one that surfaces the change.

agent update

Support summarizer

flat at ~$40/day

Docs search

flat at ~$25/day

Onboarding agent

$35 → $190/day

Fig. 1Three features on one bill. The total went up 60% and only one of them changed.

Divide by requests

A rising AI bill has two possible causes: more people used it, or each use got more expensive.

Every call carries an $ai_trace_id that groups it with one interaction. Distinct traces give you the denominator to divide by:

  • More traces means you're growing
  • More cost per trace means something regressed

If your product is a multi-turn chat, $ai_session_id groups traces into a whole conversation, and cost per session is the number you should pay attention to.

Input-to-output token ratio is worth the same treatment:

  • Output tokens rising means the model got chattier
  • Input tokens rising while output holds steady means your context is growing

What the breakdown catches

Four things account for most surprise bills, and each one has a different signature in the split:

What happenedHow it shows up
A model swapCost steps up on one $ai_model, volume unchanged
A prompt that grew$ai_input_tokens climbs, output holds
Caching stopped hittingCost per call rises while token counts stay flat
A retry loopGenerations per trace climbs, cost per trace with it

Retry loops are the expensive ones, because it looks like usage. Every failed attempt bills, and if your code retries silently the only trace of the failure is the invoice.

Build the dashboard

Add all of this data into an AI Observability dashboard you can open when you need to understand your AI spend.

The following prompt will build that dashboard for you:

Prompt for PostHog AI
Build me an AI cost dashboard from my $ai_generation events. First list the custom properties on those events and pick the one that identifies which feature made the call. Include daily total $ai_total_cost_usd; cost broken down by that feature property, by $ai_model, and by the top 20 distinct_ids; cost per trace using distinct $ai_trace_id as the denominator; and the input-to-output token ratio over time. Exclude events from dev and local environments. Then tell me which single breakdown accounts for the largest share of the last 7 days. If my project has no real $ai_generation traffic yet, build the full dashboard anyway and tell me how to instrument AI observability using the wizard or manual install.
Build this with PostHog AIIt builds the insights and the dashboard, then tells you which breakdown dominates.

Needs AI Observability instrumented.

npx @posthog/wizard ai-observability
Attribute AI cost to users and featuresBuild this with PostHog AI