MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / estimate_input_cost

Function estimate_input_cost

uncommon_route/cache_support.py:407–428  ·  view source on GitHub ↗
(
    *,
    input_tokens_uncached: int,
    cache_read_input_tokens: int,
    cache_write_input_tokens: int,
    pricing: ModelPricing,
)

Source from the content-addressed store, hash-verified

405
406
407def estimate_input_cost(
408 *,
409 input_tokens_uncached: int,
410 cache_read_input_tokens: int,
411 cache_write_input_tokens: int,
412 pricing: ModelPricing,
413) -> float:
414 cached_read_price = (
415 pricing.cached_input_price
416 if pricing.cached_input_price is not None
417 else pricing.input_price
418 )
419 cache_write_price = (
420 pricing.cache_write_price
421 if pricing.cache_write_price is not None
422 else pricing.input_price
423 )
424 return (
425 (input_tokens_uncached / 1_000_000) * pricing.input_price
426 + (cache_read_input_tokens / 1_000_000) * cached_read_price
427 + (cache_write_input_tokens / 1_000_000) * cache_write_price
428 )
429
430
431def estimate_usage_cost(

Callers 2

parse_usage_metricsFunction · 0.85
estimate_usage_costFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected