The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(logging): report the pay-as-you-go entry billing used on Azure PTU spillover (#47567)
Kerry Lu422252326153
diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.pyindex e2eed3cf6d5..78ff073fdcb 100644--- a/litellm/litellm_core_utils/litellm_logging.py+++ b/litellm/litellm_core_utils/litellm_logging.py@@ -1990,7 +1990,7 @@ class Logging(LiteLLMLoggingBaseClass):router_model_id = self.get_router_model_id()## RESPONSE COST ##- custom_pricing: Final = self._custom_pricing_for(priced_result)+ custom_pricing: Final = self.custom_pricing_for(priced_result)prompt: Final = self._prompt_for_cost_calculation()@@ -2165,7 +2165,7 @@ class Logging(LiteLLMLoggingBaseClass):model=model,completion_response=result,custom_llm_provider=custom_llm_provider,- custom_pricing=self._custom_pricing_for(result),+ custom_pricing=self.custom_pricing_for(result),base_model=get_base_model_from_metadata(model_call_details=self.model_call_details),router_model_id=router_model_id or self.get_router_model_id(),region_name=_resolve_mantle_region_for_cost(@@ -2190,7 +2190,7 @@ class Logging(LiteLLMLoggingBaseClass):usage=usage,)- def _custom_pricing_for(self, result: object) -> bool:+ def custom_pricing_for(self, result: object) -> bool:litellm_params: Final = getattr(self, "litellm_params", None)result_hidden_params: Final = getattr(result, HIDDEN_PARAMS_ATTR, None) or MappingProxyType({})additional_headers: Final = (@@ -7201,7 +7201,7 @@ def get_standard_logging_object_payload(# Fall back to the actual deployment model set by the router in metadata.if base_model is None:base_model = metadata.get("deployment")- custom_pricing: Final = use_custom_pricing_for_model(litellm_params=litellm_params)+ custom_pricing: Final = logging_obj.custom_pricing_for(init_response_obj)raw_response_cost: Final = kwargs.get("response_cost")llm_response_cost: Final[float] = raw_response_cost or 0.0guardrail_cost: Final = guardrail_information_cost(metadata.get("standard_logging_guardrail_information"))diff --git a/tests/unit/litellm_core_utils/test_litellm_logging.py b/tests/unit/litellm_core_utils/test_litellm_logging.pyindex 9d651b4ae3e..7aac43298d4 100644--- a/tests/unit/litellm_core_utils/test_litellm_logging.py+++ b/tests/unit/litellm_core_utils/test_litellm_logging.py@@ -10095,6 +10095,40 @@ class TestAzurePTUSpilloverCost:finally:self._unregister_models()+ def test_spillover_payload_reports_the_pay_as_you_go_entry_billing_used(self, monkeypatch) -> None:+ self._register_models()+ try:+ obj = self._logging_obj(dict(self.PTU_MODEL_INFO), flag="True", litellm_rate=0.0, monkeypatch=monkeypatch)+ response = self._response()+ response._hidden_params["additional_headers"] = {"llm_provider-x-ms-is-spilled-over": "true"}+ response_cost: Final = obj.response_cost_calculator(result=response)++ payload: Final = get_standard_logging_object_payload(+ kwargs={+ "model": self.SERVED_MODEL,+ "custom_llm_provider": "azure",+ "litellm_params": obj.litellm_params,+ "response_cost": response_cost,+ },+ init_response_obj=response,+ start_time=datetime.datetime.now(),+ end_time=datetime.datetime.now(),+ logging_obj=obj,+ status="success",+ )++ assert response_cost == pytest.approx(self.EXPECTED_SPILL_COST)+ assert payload is not None+ model_map_value: Final = payload["model_map_information"]["model_map_value"]+ assert model_map_value is not None+ assert model_map_value["input_cost_per_token"] == litellm.model_cost[self.SERVED_MODEL]["input_cost_per_token"]+ assert model_map_value["output_cost_per_token"] == litellm.model_cost[self.SERVED_MODEL]["output_cost_per_token"]+ assert response_cost == pytest.approx(+ 100 * model_map_value["input_cost_per_token"] + 50 * model_map_value["output_cost_per_token"]+ )+ finally:+ self._unregister_models()+def test_spillover_header_does_not_touch_non_ptu_custom_pricing(self, monkeypatch) -> None:self._register_models()custom_model_id: Final = "non-ptu-custom-router-model-id"