From 8d0820dca3fc2df03d238f8ce77461b809bafc33 Mon Sep 17 00:00:00 2001 From: Anuj7411 Date: Tue, 18 Aug 2026 23:56:47 +0530 Subject: [PATCH] fix(vertex): bill Live API output cost when input_cost_per_token is zero --- ...tex_ai_live_passthrough_logging_handler.py | 4 +++- .../test_vertex_ai_live_passthrough.py | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/vertex_ai_live_passthrough_logging_handler.py b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/vertex_ai_live_passthrough_logging_handler.py index e26f5f57532..361d97af826 100644 --- a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/vertex_ai_live_passthrough_logging_handler.py +++ b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/vertex_ai_live_passthrough_logging_handler.py @@ -151,7 +151,9 @@ class VertexAILivePassthroughLoggingHandler(BasePassthroughLoggingHandler): verbose_proxy_logger.debug("Vertex AI Live API model info for '%s': %s", model, model_info) # Check if pricing info is available - if not model_info or not model_info.get("input_cost_per_token"): + if not model_info or ( + not model_info.get("input_cost_per_token") and not model_info.get("output_cost_per_token") + ): verbose_proxy_logger.error("No pricing info found for %s in local model pricing database", model) return 0.0 diff --git a/tests/pass_through_unit_tests/test_vertex_ai_live_passthrough.py b/tests/pass_through_unit_tests/test_vertex_ai_live_passthrough.py index 9e9dd3cbe05..3dd553a5612 100644 --- a/tests/pass_through_unit_tests/test_vertex_ai_live_passthrough.py +++ b/tests/pass_through_unit_tests/test_vertex_ai_live_passthrough.py @@ -227,6 +227,27 @@ class TestVertexAILivePassthroughLoggingHandler: assert cost >= expected_min_cost assert cost > 0 + @patch( + "litellm.proxy.pass_through_endpoints.llm_provider_handlers.vertex_ai_live_passthrough_logging_handler.get_model_info" + ) + def test_calculate_cost_input_free_output_priced(self, mock_get_model_info, handler): + """A model free on input but priced on output must still bill output, not return 0.""" + mock_get_model_info.return_value = { + "input_cost_per_token": 0.0, + "output_cost_per_token": 0.000005, + } + + usage_metadata = { + "promptTokenCount": 1000, + "candidatesTokenCount": 200, + "totalTokenCount": 1200, + } + + cost = handler._calculate_live_api_cost("gemini-live-x", usage_metadata) + + assert cost == pytest.approx(200 * 0.000005) + assert cost > 0 + @patch( "litellm.proxy.pass_through_endpoints.llm_provider_handlers.vertex_ai_live_passthrough_logging_handler.get_model_info" )