This commit is contained in:
Anuj ojha 2026-09-13 00:03:35 -07:00 committed by GitHub
commit 42fbfbebde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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

@ -224,6 +224,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"
)