Skip to main content

Module usage_cost

Module usage_cost 

Source
Expand description

Provider-normalized token usage and shared raw/cache-aware USD estimates.

Structs§

SessionCostAccumulator
Accumulates independently priced turns without repricing earlier model routes. Once a turn cannot be priced, a complete session total remains unknown.
SessionCostEstimate
Cache-aware and conservative session cost estimates in USD.

Constants§

DEFAULT_CACHE_WRITE_MULTIPLIER
Default cache-write multiplier versus uncached input (5m TTL).
EXTENDED_TTL_CACHE_WRITE_MULTIPLIER
Anthropic 1h extended-TTL cache writes cost 2x base input.

Functions§

cache_write_rate
Effective cache-write rate. extended_ttl selects the 2x 1h multiplier when the catalog does not declare an explicit write rate.
estimate_session_costs
Resolve pricing for provider/model and estimate session costs from accumulated harness usage. Returns None when the model cannot be resolved or pricing metadata is unavailable.
estimate_session_costs_with_pricing
Estimate session costs from an already-resolved ModelPricing.
normalized_turn_usage
Build a per-turn harness Usage sample from raw provider usage, applying the provider-specific normalization documented on provider_reports_exclusive_input so input_tokens always represents the total prompt token count across every provider.
prompt_tokens_for_rate_limit
Prompt volume that counts toward provider TPM-style rate limits. Cached and cache-write tokens are cheaper but still consume provider capacity.
provider_reports_exclusive_input
Returns true when provider reports prompt_tokens exclusive of cache-read and cache-creation tokens.
require_budget_pricing
Reject a priced session budget when its selected route cannot be priced. Call before any inference, including automatic compaction.