diff --git a/ui/litellm-dashboard/src/components/view_logs/CostBreakdownViewer.tsx b/ui/litellm-dashboard/src/components/view_logs/CostBreakdownViewer.tsx index 61699cb2ef5..a9ce90a73f0 100644 --- a/ui/litellm-dashboard/src/components/view_logs/CostBreakdownViewer.tsx +++ b/ui/litellm-dashboard/src/components/view_logs/CostBreakdownViewer.tsx @@ -4,6 +4,8 @@ import { formatNumberWithCommas } from "@/utils/dataUtils"; export interface CostBreakdown { input_cost?: number; + cache_read_cost?: number; + cache_creation_cost?: number; output_cost?: number; total_cost?: number; tool_usage_cost?: number; @@ -22,6 +24,9 @@ interface CostBreakdownViewerProps { promptTokens?: number; completionTokens?: number; cacheHit?: string; + rawInputTokens?: number; + cacheReadTokens?: number; + cacheCreationTokens?: number; } const formatCost = (cost: number | undefined): string => { @@ -40,6 +45,9 @@ export const CostBreakdownViewer: React.FC = ({ promptTokens, completionTokens, cacheHit, + rawInputTokens, + cacheReadTokens, + cacheCreationTokens, }) => { const isCached = cacheHit?.toLowerCase() === "true"; const hasTokenCounts = promptTokens !== undefined || completionTokens !== undefined; @@ -105,17 +113,63 @@ export const CostBreakdownViewer: React.FC = ({
{/* Step 1: Base Token Costs */}
-
- Input Cost: - - {formatCost(inputCost)} - {promptTokens !== undefined && ( - - ({promptTokens.toLocaleString()} prompt tokens) + {(() => { + const hasCacheBreakdown = + costBreakdown?.cache_read_cost !== undefined || + costBreakdown?.cache_creation_cost !== undefined; + if (hasCacheBreakdown) { + // Separate line items: Input / Cache Read / Cache Write + const rawCost = isCached ? 0 : (inputCost ?? 0) - (costBreakdown?.cache_read_cost ?? 0) - (costBreakdown?.cache_creation_cost ?? 0); + return ( + <> +
+ Input Cost: + + {formatCost(rawCost)} + {rawInputTokens !== undefined && rawInputTokens !== null && ( + ({rawInputTokens.toLocaleString()} tokens) + )} + +
+ {(costBreakdown?.cache_read_cost ?? 0) > 0 && ( +
+ Cache Read Cost: + + {formatCost(isCached ? 0 : costBreakdown?.cache_read_cost)} + {(cacheReadTokens ?? 0) > 0 && ( + ({(cacheReadTokens ?? 0).toLocaleString()} tokens) + )} + +
+ )} + {(costBreakdown?.cache_creation_cost ?? 0) > 0 && ( +
+ Cache Write Cost: + + {formatCost(isCached ? 0 : costBreakdown?.cache_creation_cost)} + {(cacheCreationTokens ?? 0) > 0 && ( + ({(cacheCreationTokens ?? 0).toLocaleString()} tokens) + )} + +
+ )} + + ); + } + return ( +
+ Input Cost: + + {formatCost(inputCost)} + {promptTokens !== undefined && ( + + ({promptTokens.toLocaleString()} prompt tokens) + + )} - )} - -
+
+ ); + })()}
Output Cost: