Skip to content

Display cost tracking in the UI#6314

Draft
AntoineToussaint wants to merge 6 commits intotensorzero:mainfrom
AntoineToussaint:cost-tracking-frontend-aggregation
Draft

Display cost tracking in the UI#6314
AntoineToussaint wants to merge 6 commits intotensorzero:mainfrom
AntoineToussaint:cost-tracking-frontend-aggregation

Conversation

@AntoineToussaint
Copy link

Summary

  • Display per-inference cost on inference detail pages
  • Display aggregate cost by variant on function detail pages (stacked area chart)
  • Display cost on variant detail pages (filtered to selected variant)
  • Adaptive decimal formatting for small costs (e.g. $0.000012)
  • Show cost coverage: fraction of inferences with/without cost data
  • Time granularity selector for cost charts

TODO before merging

  • Move ChartLegendList out of generic chart.tsx: Currently the cost-specific legend component (ChartLegendList) lives in ui/app/components/ui/chart.tsx. It should be a local component in VariantCost.tsx instead — generic chart components should not be modified for feature-specific needs.
  • Revert PieChart.tsx changes: ui/app/components/experimentation/PieChart.tsx was modified to use ChartLegendList instead of the original Recharts ChartLegend/ChartLegendContent. This should be reverted back to its original state.

Test plan

  • Navigate to a function page with cost-configured variants and verify the cost chart renders
  • Navigate to a variant detail page and verify cost chart filters to that variant
  • Verify adaptive decimals display correctly for very small costs
  • Verify the "X of Y inferences have cost data" coverage message
  • Verify the Variant Weights pie chart on function pages still renders correctly

Made with Cursor

Antoine Toussaint and others added 6 commits February 11, 2026 17:09
Add the ability to configure per-provider cost tracking using JSON Pointer
mappings from raw provider responses. Cost is computed at inference time
and stored in both ClickHouse and Postgres as Decimal(18, 9).

Key changes:
- New `cost` module with config types, computation, and validation
- Support for `cost_per_million` and `cost_per_unit` rate types
- Split pointer config for streaming vs non-streaming responses
- Negative rates allowed (caching discounts); negative totals → None
- DB migrations for ClickHouse (migration 0046) and Postgres
- Cost field threaded through all providers, variants, and inference types
- 22 unit tests covering computation, edge cases, and TOML deserialization

Closes tensorzero#6260, closes tensorzero#6261

Co-authored-by: Cursor <cursoragent@cursor.com>
Show per-inference and per-model-inference cost in the observability UI
when cost tracking is configured for the model provider.

Key changes:
- `formatCost` utility with adaptive precision (8 decimal places for tiny
  costs, 2 for large), negative cost support, and NaN/Infinity guards
- `getTotalInferenceUsage` aggregates cost with partial-sum semantics
  (sums known values; null only when ALL inferences lack cost data)
- CostIcon SVG component and cost Chip in BasicInfo and ModelInferenceItem
- Manually patched TS bindings for `Usage.cost` and `ModelInference.cost`
  (temporary workaround for ts-rs build issue with CostConfigEntry)
- 56 unit tests for formatCost and getTotalInferenceUsage

Closes tensorzero#6263

Co-authored-by: Cursor <cursoragent@cursor.com>
- Add getFunctionCostByVariant client and VariantCost types
- VariantCostChart: stacked area chart with cost by variant and time
- Cost section on function detail page (below Throughput)
- Graceful fallback when cost_by_variant endpoint is not available

Co-authored-by: Cursor <cursoragent@cursor.com>
- Add Cost section to variant detail page (loader + CostSection with VariantCostChart)
- Fix VariantCost.tsx: use ChartLegend with items/colors (ChartLegendContent is not exported)

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
… fix (tensorzero#6264)

- Add costDecimalPlaces + formatCostForChart in utils/chart for adaptive $ display
- Add ChartLegendList in chart.tsx (standalone legend, no Recharts payload); use in VariantCost + PieChart
- VariantCost: total cost line, totalInferenceCount for empty state (0 of N, 100% without cost)
- Show fraction without cost when partial (X of Y have cost, Z% without cost)
- Function page: pass totalInferenceCount to VariantCostChart
- Y-axis: position outsideLeft, width 88 to fix overlap with Cost ($) label
- PieChart: use ChartLegendList outside ChartContainer to fix layout

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the Contributor License Agreement (CLA) and hereby sign the CLA.


1 out of 2 committers have signed the CLA.
✅ (AntoineToussaint)[https://github.com/AntoineToussaint]
@antoine Toussaint
Antoine Toussaint seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant