fix(vertex): bill Live API output cost when input_cost_per_token is zero

This commit is contained in:
Anuj7411 2026-08-18 23:56:47 +05:30
parent 4fd7a73ef5
commit 8d0820dca3
2 changed files with 24 additions and 1 deletions

View file

@ -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

View file

@ -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"
)