mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-05 02:41:56 +00:00
fix(cost): always call get_cost_for_built_in_tools to avoid under-counting
Revert the guard that skipped built-in tool cost when standard_built_in_tools_params was falsy. get_cost_for_built_in_tools can return non-zero from response/usage alone (e.g. web search) even when params is None/empty, so skipping the call caused under-counting. Keep discount/margin/logging_obj guards (crash fix + optimization).
This commit is contained in:
parent
b8380f237d
commit
535f721849
1 changed files with 10 additions and 11 deletions
|
|
@ -1325,18 +1325,17 @@ def completion_cost( # noqa: PLR0915
|
|||
_final_cost = (
|
||||
prompt_tokens_cost_usd_dollar + completion_tokens_cost_usd_dollar
|
||||
)
|
||||
if standard_built_in_tools_params:
|
||||
cost_for_built_in_tools = (
|
||||
StandardBuiltInToolCostTracking.get_cost_for_built_in_tools(
|
||||
model=model,
|
||||
response_object=completion_response,
|
||||
usage=cost_per_token_usage_object,
|
||||
standard_built_in_tools_params=standard_built_in_tools_params,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
)
|
||||
# Always call: get_cost_for_built_in_tools can return non-zero from
|
||||
# response/usage alone (e.g. web search) even when params is None/empty.
|
||||
cost_for_built_in_tools = (
|
||||
StandardBuiltInToolCostTracking.get_cost_for_built_in_tools(
|
||||
model=model,
|
||||
response_object=completion_response,
|
||||
usage=cost_per_token_usage_object,
|
||||
standard_built_in_tools_params=standard_built_in_tools_params,
|
||||
custom_llm_provider=custom_llm_provider,
|
||||
)
|
||||
else:
|
||||
cost_for_built_in_tools = 0.0
|
||||
)
|
||||
_final_cost += cost_for_built_in_tools
|
||||
|
||||
# Apply discount from module-level config if configured
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue