:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(aio): make the llm cost regression steps carry their own queries (#99521)
posthog[bot]b9b95ed86666
diff --git a/products/ai_observability/skills/exploring-llm-costs/references/regression-debugging.md b/products/ai_observability/skills/exploring-llm-costs/references/regression-debugging.mdindex cbec9617a467..854390c2b2ff 100644--- a/products/ai_observability/skills/exploring-llm-costs/references/regression-debugging.md+++ b/products/ai_observability/skills/exploring-llm-costs/references/regression-debugging.md@@ -24,9 +24,24 @@ doubled, it's volume; if cost-per-call rose, it's prompt size, model, or cache.## Step 2 — Look for a model mix shift-Run the "cost by model" recipe in [breakdown patterns](./breakdown-patterns.md)-over two windows — the week before and the week after the jump — and diff. A-new `$ai_model` value appearing, or an old one disappearing, is a strong signal.+```sql+posthog:execute-sql+SELECT+ toDate(timestamp) AS day,+ properties.$ai_model AS model,+ count() AS calls,+ round(sum(toFloat(properties.$ai_total_cost_usd)), 4) AS cost_usd,+ round(avg(toFloat(properties.$ai_total_cost_usd)), 6) AS avg_cost_per_call+FROM events+WHERE event IN ('$ai_generation', '$ai_embedding')+ AND timestamp >= now() - INTERVAL 60 DAY+GROUP BY day, model+ORDER BY day, model+```++A model appearing or disappearing around the jump is a strong signal. So is a+model taking a bigger share of `calls` or `cost_usd` after it, even when its+own `avg_cost_per_call` held steady.## Step 3 — Look for prompt bloat@@ -46,10 +61,34 @@ ORDER BY day, model## Step 4 — Look for cache degradation-Rerun the "input vs output vs cache economics" recipe in-[breakdown patterns](./breakdown-patterns.md) windowed by day and track-`cache_hit_rate`. A drop often follows a system-prompt change that invalidated-the cached prefix.+```sql+posthog:execute-sql+SELECT+ toDate(timestamp) AS day,+ properties.$ai_model AS model,+ round(+ if(+ any(properties.$ai_cache_reporting_exclusive) = 'true',+ sum(toInt(properties.$ai_cache_read_input_tokens))+ / nullIf(sum(toInt(properties.$ai_input_tokens))+ + sum(toInt(properties.$ai_cache_read_input_tokens))+ + sum(toInt(properties.$ai_cache_creation_input_tokens)), 0),+ sum(toInt(properties.$ai_cache_read_input_tokens))+ / nullIf(sum(toInt(properties.$ai_input_tokens)), 0)+ ), 3+ ) AS cache_hit_rate,+ sum(toInt(properties.$ai_input_tokens)) AS input_tokens,+ sum(toInt(properties.$ai_cache_read_input_tokens)) AS cache_read_tokens+FROM events+WHERE event = '$ai_generation'+ AND timestamp >= now() - INTERVAL 30 DAY+GROUP BY day, model+ORDER BY day, model+```++A drop often follows a system-prompt change that invalidated the cached prefix.+A rate above 1 means the flag is unset on those events, so the inclusive+branch ran over exclusive data. Read the token columns instead.## Step 5 — Isolate the feature