mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-06 07:48:06 +00:00
Merge 250bc03936 into 4212f1af27
This commit is contained in:
commit
6eb581065c
2 changed files with 23 additions and 2 deletions
|
|
@ -38,11 +38,11 @@ from litellm.litellm_core_utils.llm_cost_calc.utils import (
|
|||
BilledTokenRates,
|
||||
CostCalculatorUtils,
|
||||
calculate_cache_writing_cost,
|
||||
calculate_cost_component,
|
||||
generic_cost_per_character,
|
||||
generic_cost_per_token,
|
||||
get_batch_cost_rates,
|
||||
get_billable_input_tokens,
|
||||
get_cost_per_unit,
|
||||
get_regional_uplift_multiplier,
|
||||
get_service_tier_cost_key,
|
||||
get_token_type_cost_breakdown,
|
||||
|
|
@ -3040,7 +3040,10 @@ def batch_cost_calculator(
|
|||
|
||||
# Add cache read cost if applicable
|
||||
cache_read_cost_key: Final = get_service_tier_cost_key("cache_read_input_token_cost", None)
|
||||
total_prompt_cost += calculate_cost_component(model_info, cache_read_cost_key, cache_read_tokens) / 2
|
||||
cache_read_cost: Final = get_cost_per_unit(model_info, cache_read_cost_key, None)
|
||||
total_prompt_cost += (
|
||||
cache_read_tokens * (input_cost_per_token if cache_read_cost is None else cache_read_cost) / 2
|
||||
)
|
||||
|
||||
cache_creation_cost: Final = model_info.get("cache_creation_input_token_cost") or input_cost_per_token
|
||||
total_prompt_cost += cache_creation_tokens * cache_creation_cost / 2
|
||||
|
|
|
|||
|
|
@ -4310,6 +4310,24 @@ def test_batch_cost_calculator_cache_creation_falls_back_to_input_rate():
|
|||
assert prompt_cost == pytest.approx((1000 * 3e-6 + 8000 * 3e-7 + 2000 * 3e-6) / 2)
|
||||
|
||||
|
||||
def test_batch_cost_calculator_cache_read_falls_back_to_input_rate():
|
||||
from litellm.cost_calculator import batch_cost_calculator
|
||||
|
||||
model_info: ModelInfo = {
|
||||
"supported_openai_params": [],
|
||||
"input_cost_per_token": 3e-6,
|
||||
"output_cost_per_token": 15e-6,
|
||||
}
|
||||
prompt_cost, _ = batch_cost_calculator(
|
||||
usage=_batch_cache_usage(),
|
||||
model="my-fine-tuned-model",
|
||||
custom_llm_provider="openai",
|
||||
model_info=model_info,
|
||||
)
|
||||
|
||||
assert prompt_cost == pytest.approx(11000 * 3e-6 / 2)
|
||||
|
||||
|
||||
def test_completion_cost_bills_interactions_api_response():
|
||||
from litellm.types.interactions import InteractionsAPIResponse
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue