@@ -9,6 +9,7 @@ namespace DevProxy.Abstractions.LanguageModel;
99public class ModelPrices
1010{
1111 public double Input { get ; set ; }
12+ public double CachedInput { get ; set ; }
1213 public double Output { get ; set ; }
1314}
1415
@@ -44,7 +45,7 @@ public bool TryGetModelPrices(string modelName, out ModelPrices? prices)
4445 return false ;
4546 }
4647
47- public ( double Input , double Output ) CalculateCost ( string modelName , long inputTokens , long outputTokens )
48+ public ( double Input , double Output ) CalculateCost ( string modelName , long inputTokens , long outputTokens , long cachedInputTokens = 0 )
4849 {
4950 if ( ! TryGetModelPrices ( modelName , out var prices ) )
5051 {
@@ -54,7 +55,14 @@ public bool TryGetModelPrices(string modelName, out ModelPrices? prices)
5455 Debug . Assert ( prices != null , "Prices data should not be null here." ) ;
5556
5657 // Prices in the data are per 1M tokens
57- var inputCost = prices . Input * ( inputTokens / 1_000_000.0 ) ;
58+ // When cached input pricing is available, separate cached tokens
59+ // from regular input tokens for accurate cost calculation
60+ var regularInputTokens = inputTokens - cachedInputTokens ;
61+ var inputCost = prices . Input * ( regularInputTokens / 1_000_000.0 ) ;
62+ if ( cachedInputTokens > 0 && prices . CachedInput > 0 )
63+ {
64+ inputCost += prices . CachedInput * ( cachedInputTokens / 1_000_000.0 ) ;
65+ }
5866 var outputCost = prices . Output * ( outputTokens / 1_000_000.0 ) ;
5967
6068 return ( inputCost , outputCost ) ;
0 commit comments