exploring-llm-costs
What it does
This skill answers questions about what your AI model usage costs, using the cost data PostHog records for each model call. It is for anyone who manages AI budgets or wants to know which model or feature is most expensive.
When to use it
- βWhen you want to know how much your team spends on AI models over time.
- βWhen costs jumped and you need to know which model, user or feature caused it.
- βWhen you want a cost chart or alert to keep an eye on AI spending.
Skill link
https://github.com/PostHog/posthog/blob/master/products/ai_observability/skills/exploring-llm-costs/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHow much did we spend on AI models last month, and which model cost the most?β
5 new skills a week. 1 minute to read.
How it works
It totals the cost of each AI model call in PostHog and groups the totals by the choice you make, such as model, provider, user or a custom property. It can compare periods to explain spikes and save the result as a chart or dashboard item.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Exploring LLM costs
PostHog attaches per-call cost metadata to every $ai_generation and $ai_embedding
event at ingestion time. Every cost question reduces to an aggregation over those
two event types β the interesting variation is only in how you group, filter, and
compare.
This skill covers the common cost investigations: total spend, breakdowns (model, provider, user, trace, custom property), token and cache-hit analysis, regression debugging, and materializing results as insights, dashboards, or alerts.
Tools
| Tool | Purpose |
|---|---|
posthog:query-trends |
Native cost trends with supported sums, breakdowns, and comparisons |
posthog:execute-sql |
Ad-hoc HogQL for any cost aggregation β the workhorse of this skill |
posthog:query-llm-traces-list |
List traces with rolled-up cost, token, and error metrics |
posthog:query-llm-trace |
Cost breakdown of a single trace across all its events |
posthog:read-data-schema |
Discover which custom properties exist for breakdowns |
posthog:insight-create |
Materialize a cost chart as a saved insight |
posthog:dashboard-create |
Bundle cost insights into a dashboard |
posthog:alert-create |
Alert when cost crosses a threshold |
posthog:generate-app-url |
Build region- and project-qualified links back to the UI |
Core rules
Three rules cover most of what goes wrong:
- Sum
$ai_total_cost_usdfor rollups, never the components. Components drop request and web-search fees. The UI's cost cells sum$ai_total_cost_usdoverevent IN ('$ai_generation', '$ai_embedding'); mirror that. Full schema and rationale in cost properties. - Always include both
$ai_generationand$ai_embeddingin cost queries unless the project demonstrably does not use embeddings β missing them silently under-counts.$ai_traceand$ai_spancarry no rollup cost; some SDK wrappers duplicate$ai_total_cost_usdonto$ai_traceso don't include it in rollups or you'll double-count. - Always set a time range. Cost queries without one scan the full events table.
$ai_total_cost_usd is set at ingestion via one of three paths (passthrough,
custom pricing, automatic lookup). When a cost looks wrong, read
$ai_cost_model_source first β see cost sources
for the precedence rules and a diagnostic query.
Cache-hit math depends on whether the provider reports cache tokens inclusively
or exclusively of $ai_input_tokens. Always branch on the per-event
$ai_cache_reporting_exclusive flag, never on provider name β see
cache accounting for the exclusive-vs-inclusive
formula.
distinct_id is the canonical user dimension. Customers often attach custom
properties (feature, tenant_id, workflow_name) β discover them with
posthog:read-data-schema before grouping. Don't guess names.
Workflow: total spend in a window
posthog:execute-sql
SELECT round(sum(toFloat(properties.$ai_total_cost_usd)), 4) AS total_cost_usd
FROM events
WHERE event IN ('$ai_generation', '$ai_embedding')
AND timestamp >= now() - INTERVAL 30 DAY
Workflow: cost breakdowns
Every cost question is a variation of the same template β group by a dimension,
aggregate $ai_total_cost_usd. See breakdown patterns
for ready-to-run recipes:
- Cost over time (daily)
- Cost by model
- Cost by user (top spenders)
- Cost by trace (top expensive traces)
- Cost by custom dimension
- Cost-per-call distribution
- Input vs output vs cache economics
Workflow: inspect a single trace's cost
When the user pastes a trace URL and asks about its cost, fetch the trace and surface the per-event breakdown:
posthog:query-llm-trace
{ "traceId": "<trace_id>", "dateRange": {"date_from": "-30d"} }
Sum $ai_total_cost_usd across the returned events, grouped by span name or
model, to show which step(s) drove the cost. The trace response already
includes totalCost as a convenience.
Workflow: debug a cost regression
"Our LLM bill jumped β w
FAQ
Where does the cost number come from?
PostHog attaches cost information to each AI call when it is recorded, so the totals come from that data.
Can it also show token usage?
Yes. It can look at tokens and cache hits along with cost.
Can I put this on a dashboard?
Yes. It can save a cost chart as an insight and add it to a dashboard.
Details
Original description by the author
Investigate LLM spend in PostHog β total cost over time, cost by model, provider, user, trace, or custom dimension, token and cache-hit economics, and cost regressions. Use when the user asks "how much are we spending on LLMs?", "which model / user / feature is most expensive?", "why did cost spike?", wants to build a cost dashboard or alert, or pastes a trace URL and asks about its cost.
repo: PostHog/posthog
Popularity
- GitHub stars
- 41k
- Ranking position
- #6831
- License
- β
- Updated
- 11/2/2026
Comments
- β¦
More skills from this repository
depot-ci
41kHelps your agent set up and run Depot CI workflows, a GitHub Actions alternative, including migrating existing workflows and reading run logs.
depot-container-builds
41kHelps your agent build Docker images on Depot's remote builders, including multi-platform images, pushing to registries, and fixing build failures.
depot-github-runners
41kHelps your agent move GitHub Actions jobs to Depot-managed runners, choosing runner sizes and labels, and troubleshooting runner setup issues.
editing-agents-md
41kHelps your agent decide whether a rule belongs in an AGENTS.md or CLAUDE.md file, and write it so it sticks without bloating the file.
Similar skills
gitcrawl
394kLets your agent search a saved archive of GitHub issues and pull requests, group duplicates, and check their current status on GitHub.
slacrawl
394kLets your agent search and count messages in a local Slack archive, check how fresh that archive is, and refresh it when needed.
goplaces
394kHelps your agent search for places, get their details and reviews, and resolve place names using Google Places, with JSON output for scripts.