Display cost tracking in the UI#6314
Display cost tracking in the UI#6314AntoineToussaint wants to merge 6 commits intotensorzero:mainfrom
Conversation
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>
|
I have read the Contributor License Agreement (CLA) and hereby sign the CLA. 1 out of 2 committers have signed the CLA. |
Summary
TODO before merging
ChartLegendListout of genericchart.tsx: Currently the cost-specific legend component (ChartLegendList) lives inui/app/components/ui/chart.tsx. It should be a local component inVariantCost.tsxinstead — generic chart components should not be modified for feature-specific needs.PieChart.tsxchanges:ui/app/components/experimentation/PieChart.tsxwas modified to useChartLegendListinstead of the original RechartsChartLegend/ChartLegendContent. This should be reverted back to its original state.Test plan
Made with Cursor