mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
fix: use is-not-None guards for per-second cost extraction
Greptile review (confidence 3/5) correctly identified that the input_cost_per_second / output_cost_per_second fallback used the Python operator, which treats 0.0 as falsy — the same bug explicitly fixed for token-based pricing in this PR. Replace with explicit checks so a configured input_cost_per_second of 0.0 (free input) is honoured rather than silently falling back to output_cost_per_second.
This commit is contained in:
parent
a5a69b08c1
commit
af8b79eb5b
1 changed files with 8 additions and 3 deletions
|
|
@ -1139,9 +1139,14 @@ def completion_cost( # noqa: PLR0915
|
|||
_metadata = _litellm_params.get("metadata", {}) or {}
|
||||
_model_info = _metadata.get("model_info", {}) or {}
|
||||
# Prefer input_cost_per_second; fall back to output_cost_per_second
|
||||
_cost_per_second = _model_info.get(
|
||||
"input_cost_per_second"
|
||||
) or _model_info.get("output_cost_per_second")
|
||||
# Use `is not None` guards to correctly handle explicit 0.0 costs
|
||||
_input_cost_per_second = _model_info.get("input_cost_per_second")
|
||||
_output_cost_per_second = _model_info.get("output_cost_per_second")
|
||||
_cost_per_second = (
|
||||
_input_cost_per_second
|
||||
if _input_cost_per_second is not None
|
||||
else _output_cost_per_second
|
||||
)
|
||||
if _cost_per_second is not None:
|
||||
custom_cost_per_second = _cost_per_second
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue