Skip to content

Commit 6e64f46

Browse files
Simplify cached input cost calculation
1 parent 73194c7 commit 6e64f46

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

DevProxy.Abstractions/LanguageModel/PricesData.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,13 @@ public bool TryGetModelPrices(string modelName, out ModelPrices? prices)
5454

5555
Debug.Assert(prices != null, "Prices data should not be null here.");
5656

57-
// Prices in the data are per 1M tokens
58-
// When cached input pricing is available, separate cached tokens
59-
// from regular input tokens for accurate cost calculation
57+
// Prices in the data are per 1M tokens.
58+
// When no cached input price is configured, fall back to the
59+
// regular input price so all tokens are billed correctly.
60+
var effectiveCachedPrice = prices.CachedInput > 0 ? prices.CachedInput : prices.Input;
6061
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-
}
62+
var inputCost = (prices.Input * (regularInputTokens / 1_000_000.0))
63+
+ (effectiveCachedPrice * (cachedInputTokens / 1_000_000.0));
6664
var outputCost = prices.Output * (outputTokens / 1_000_000.0);
6765

6866
return (inputCost, outputCost);

0 commit comments

Comments
 (0)