mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 04:12:10 +03:00
fix(cost): prevent double-billing of cache_creation_input_tokens (#2522)
fix(cost): prevent double-billing of cache_creation_input_tokens — integrated into release/v3.8.2
This commit is contained in:
committed by
GitHub
parent
2fc8f9e9b9
commit
a2efaf384c
@@ -94,7 +94,12 @@ export function computeCostFromPricing(
|
||||
const inputTokens = tokens.input ?? tokens.prompt_tokens ?? tokens.input_tokens ?? 0;
|
||||
const cachedTokens =
|
||||
tokens.cacheRead ?? tokens.cached_tokens ?? tokens.cache_read_input_tokens ?? 0;
|
||||
const nonCachedInput = Math.max(0, inputTokens - cachedTokens);
|
||||
const cacheCreationTokens = tokens.cacheCreation ?? tokens.cache_creation_input_tokens ?? 0;
|
||||
|
||||
// prompt_tokens from extractors already includes cache_read + cache_creation,
|
||||
// so we must subtract BOTH cache types to avoid pricing cache at the full
|
||||
// input rate in addition to their dedicated cache_* rates below.
|
||||
const nonCachedInput = Math.max(0, inputTokens - cachedTokens - cacheCreationTokens);
|
||||
cost += nonCachedInput * (inputPrice / 1_000_000);
|
||||
if (cachedTokens > 0) cost += cachedTokens * (cachedPrice / 1_000_000);
|
||||
|
||||
@@ -104,7 +109,6 @@ export function computeCostFromPricing(
|
||||
const reasoningTokens = tokens.reasoning ?? tokens.reasoning_tokens ?? 0;
|
||||
if (reasoningTokens > 0) cost += reasoningTokens * (reasoningPrice / 1_000_000);
|
||||
|
||||
const cacheCreationTokens = tokens.cacheCreation ?? tokens.cache_creation_input_tokens ?? 0;
|
||||
if (cacheCreationTokens > 0) cost += cacheCreationTokens * (cacheCreationPrice / 1_000_000);
|
||||
|
||||
return cost * getCodexFastCostMultiplier(options.provider, options.model, options.serviceTier);
|
||||
|
||||
Reference in New Issue
Block a user