From 4b75229d6e37ab15a982a51963cbecb5caf7f6be Mon Sep 17 00:00:00 2001 From: Dor Amir Date: Thu, 5 Mar 2026 12:22:15 -0500 Subject: [PATCH] fix: also extract output_cost_per_second for custom per-second pricing Per Greptile review: the previous implementation only read input_cost_per_second, missing deployments configured with output_cost_per_second only. Now falls back to output_cost_per_second when input_cost_per_second is not set. --- litellm/cost_calculator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index 0f2f48aa1dd..3184c0495ae 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -1127,8 +1127,9 @@ def completion_cost( # noqa: PLR0915 "output_cost_per_token": _output_cost if _output_cost is not None else 0.0, } # Also extract custom_cost_per_second if available + # Prefer input_cost_per_second; fall back to output_cost_per_second if custom_cost_per_second is None: - _cost_per_second = _model_info.get("input_cost_per_second") + _cost_per_second = _model_info.get("input_cost_per_second") or _model_info.get("output_cost_per_second") if _cost_per_second is not None: custom_cost_per_second = _cost_per_second