You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(webapp): add prompt-cache metrics to the prompt detail page
The prompt detail Metrics tab now shows a Cached tokens total, a cache
hit-rate-over-time chart, and a cached-tokens-over-time chart, matching
the model detail page. Avg input cost and input cost per 1k now include
the cache-read and cache-creation cost lines so they reflect total input
spend rather than the fresh-input cost alone.
Copy file name to clipboardExpand all lines: apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.prompts.$promptSlug/route.tsx
+56-3Lines changed: 56 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1626,7 +1626,7 @@ function MetricsTab({
1626
1626
return(
1627
1627
<divclassName="space-y-3">
1628
1628
{/* Summary big numbers */}
1629
-
<divclassName="grid grid-cols-4 gap-3">
1629
+
<divclassName="grid grid-cols-5 gap-3">
1630
1630
<divclassName="h-44">
1631
1631
<MetricWidget
1632
1632
widgetKey={`prompt-${prompt.slug}-generations`}
@@ -1659,7 +1659,7 @@ function MetricsTab({
1659
1659
<MetricWidget
1660
1660
widgetKey={`prompt-${prompt.slug}-cost`}
1661
1661
title="Avg input cost"
1662
-
query={`SELECT avg(input_cost) AS avg_cost FROM llm_metrics WHERE 1=1`}
1662
+
query={`SELECT avg(input_cost + cached_read_cost + cache_creation_cost) AS avg_cost FROM llm_metrics WHERE 1=1`}
1663
1663
config={{
1664
1664
type: "bignumber",
1665
1665
column: "avg_cost",
@@ -1684,6 +1684,20 @@ function MetricsTab({
1684
1684
{...widgetProps}
1685
1685
/>
1686
1686
</div>
1687
+
<divclassName="h-44">
1688
+
<MetricWidget
1689
+
widgetKey={`prompt-${prompt.slug}-cached-tokens`}
1690
+
title="Cached tokens"
1691
+
query={`SELECT sum(cached_read_tokens) AS cached_tokens FROM llm_metrics WHERE 1=1`}
1692
+
config={{
1693
+
type: "bignumber",
1694
+
column: "cached_tokens",
1695
+
aggregation: "sum",
1696
+
abbreviate: true,
1697
+
}}
1698
+
{...widgetProps}
1699
+
/>
1700
+
</div>
1687
1701
</div>
1688
1702
1689
1703
{/* Version performance */}
@@ -1808,7 +1822,7 @@ function VersionPerformanceSection({
query={`SELECT timeBucket(), prettyFormat(quantile(0.5)(input_cost / input_tokens * 1000), 'costInDollars') AS p50, prettyFormat(quantile(0.95)(input_cost / input_tokens * 1000), 'costInDollars') AS p95 FROM llm_metrics WHERE input_tokens > 0 GROUP BY timeBucket ORDER BY timeBucket`}
1825
+
query={`SELECT timeBucket(), prettyFormat(quantile(0.5)((input_cost + cached_read_cost + cache_creation_cost) / input_tokens * 1000), 'costInDollars') AS p50, prettyFormat(quantile(0.95)((input_cost + cached_read_cost + cache_creation_cost) / input_tokens * 1000), 'costInDollars') AS p95 FROM llm_metrics WHERE input_tokens > 0 GROUP BY timeBucket ORDER BY timeBucket`}
1812
1826
config={{
1813
1827
type: "chart",
1814
1828
chartType: "line",
@@ -1862,6 +1876,45 @@ function VersionPerformanceSection({
1862
1876
{...widgetProps}
1863
1877
/>
1864
1878
</div>
1879
+
{/* Row 4: Caching */}
1880
+
<divclassName="h-96">
1881
+
<MetricWidget
1882
+
widgetKey={`prompt-${promptSlug}-perf-cache-hit`}
1883
+
title="Cache hit rate over time"
1884
+
query={`SELECT timeBucket(), round(ifNull(sum(cached_read_tokens) * 100.0 / nullIf(sum(input_tokens), 0), 0), 1) AS cache_hit_pct FROM llm_metrics WHERE 1=1 GROUP BY timeBucket ORDER BY timeBucket`}
query={`SELECT timeBucket(), sum(cached_read_tokens) AS cache_reads, sum(cache_creation_tokens) AS cache_writes FROM llm_metrics WHERE 1=1 GROUP BY timeBucket ORDER BY timeBucket`}
0 commit comments