Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion litellm/llms/AzureOpenAI/cost_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def cost_per_token(
model_info = get_model_info(model=model, custom_llm_provider="azure")

## CALCULATE INPUT COST
prompt_cost: float = usage["prompt_tokens"] * model_info["input_cost_per_token"]
total_prompt_tokens: float = usage["prompt_tokens"] - usage._cache_read_input_tokens
prompt_cost: float = total_prompt_tokens * model_info["input_cost_per_token"]

## CALCULATE OUTPUT COST
completion_cost: float = (
Expand Down
3 changes: 2 additions & 1 deletion litellm/llms/OpenAI/cost_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def cost_per_token(
model_info = get_model_info(model=model, custom_llm_provider="openai")

## CALCULATE INPUT COST
prompt_cost: float = usage["prompt_tokens"] * model_info["input_cost_per_token"]
total_prompt_tokens: float = usage["prompt_tokens"] - usage._cache_read_input_tokens
prompt_cost: float = total_prompt_tokens * model_info["input_cost_per_token"]

## CALCULATE OUTPUT COST
completion_cost: float = (
Expand Down
14 changes: 9 additions & 5 deletions tests/local_testing/test_completion_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,10 +1393,13 @@ def test_cost_azure_openai_prompt_caching():
usage = response_2.usage

_expected_cost2 = (
usage.prompt_tokens * model_info["input_cost_per_token"]
+ usage.completion_tokens * model_info["output_cost_per_token"]
+ usage.prompt_tokens_details.cached_tokens
* model_info["cache_read_input_token_cost"]
(usage.prompt_tokens - usage.prompt_tokens_details.cached_tokens)
* model_info["input_cost_per_token"]
+ (usage.completion_tokens * model_info["output_cost_per_token"])
+ (
usage.prompt_tokens_details.cached_tokens
* model_info["cache_read_input_token_cost"]
)
)

print("_expected_cost2", _expected_cost2)
Expand Down Expand Up @@ -1515,7 +1518,8 @@ def test_cost_openai_prompt_caching():
usage = response_2.usage

_expected_cost2 = (
usage.prompt_tokens * model_info["input_cost_per_token"]
(usage.prompt_tokens - usage.prompt_tokens_details.cached_tokens)
* model_info["input_cost_per_token"]
+ usage.completion_tokens * model_info["output_cost_per_token"]
+ usage.prompt_tokens_details.cached_tokens
* model_info["cache_read_input_token_cost"]
Expand Down