- Use a custom property to name specific features
- Default properties like
$ai_modeland$ai_providerare included automatically distinct_idtells you which customers your spend goes to
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:
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.
Support summarizer
flat at ~$40/day
Docs search
flat at ~$25/day
Onboarding agent
$35 → $190/day
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 happened | How it shows up |
|---|---|
| A model swap | Cost steps up on one $ai_model, volume unchanged |
| A prompt that grew | $ai_input_tokens climbs, output holds |
| Caching stopped hitting | Cost per call rises while token counts stay flat |
| A retry loop | Generations 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: