mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-02 01:28:38 +00:00
| .. | ||
| benches | ||
| examples | ||
| src | ||
| tests | ||
| Cargo.toml | ||
| README.md | ||
litellm-cost
calculate(&prices, &usage, &when)consumes the samePricesthatlitellm-model-catalogproduces. There is no separate pricing specification or compilation step, and no runtime caller is migrated hereUsage::quantitiescontains disjoint billable quantities keyed byMeter, including text, audio, image, reasoning, cache reads, writes by TTL, characters, seconds, images and queries. Text counts exclude the quantities assigned to sub-meters. Provider response normalization stays with the callerprompt_tokensis the total prompt count, including cache and modalities, used only for selecting a prompt band. It is not billed a second timeinclusive_thresholdchooses>=instead of>at prompt-band boundariessearch_resultsselects a query result band. Query quantity remains the number of queries. Video-second quantity selects a duration interval
Whensupplies the service tier, channel and billing timestamp.price::Whenremains the catalog key for a tier and bandPriced::Knowncontains aBreakdown.Priced::Unpricedlists every used meter without a price and retains the priced lines and their partial total. Zero usage needs no price. An explicit zero price remains a known zero-cost line- Every line records its billed meter, quantity, unit price and amount. When a sub-meter falls back,
fallback_fromidentifies the original usage meter andmeteridentifies the price source- Audio, image and video tokens fall back to text on the same side, and reasoning falls back to text output
- Cache reads fall back to text input. Long-TTL writes fall back through the default write price to text input
- Missing non-token prices never fall back to token prices
- Online lookup preserves R1's
(tier, band),(standard, band),(tier, base),(standard, base)order before sub-meter fallback- Off-peak overrides only declared rates during matching UTC windows. Windows can wrap midnight and restrict weekdays in an IANA timezone
- Batch prices select bands per meter. Explicit batch prices win, missing input sub-meters use the batch input rate, and missing batch token rates can use half the online base rate
- Decisions use their own channel and never silently borrow online prices
Breakdown::input()sums non-output lines andoutput()sums output lines.totalsums all lines. Prices and amounts remain money newtypes withf64internally- Regional adjustments remain separate from prices. The caller selects and applies
Adjustmentswhen needed - Run
cargo run -p litellm-cost --example chargefor a normalized usage example. The existing Python reference TSV is still tested unchanged. Broader fixture generation and full Python pricing parity are deferred