diff --git a/litellm/proxy/spend_tracking/cost_compiler.py b/litellm/proxy/spend_tracking/cost_compiler.py index a0cca9c3757..d85513da70a 100644 --- a/litellm/proxy/spend_tracking/cost_compiler.py +++ b/litellm/proxy/spend_tracking/cost_compiler.py @@ -19,6 +19,7 @@ from litellm.accounting import ( Unpriced, ) from litellm.cost_calculator import batch_cost_calculator +from litellm.litellm_core_utils.hidden_params import set_hidden_param from litellm.litellm_core_utils.litellm_logging import Logging from litellm.litellm_core_utils.llm_cost_calc.finalization import finalize_cost from litellm.litellm_core_utils.llm_cost_calc.pricing_context import RetainedPricing, retained_pricing @@ -230,11 +231,8 @@ def price_usage(envelope: str) -> PricingSnapshot | Unpriced: "file_search": adjustments.get("file_search") or None, } ) - logger.record_provider_reported_cost( - TypeAdapter[float | None](float | None).validate_python( - logged.get("provider_reported_cost") if upstream else None - ) - ) + if upstream and logged.get("provider_reported_cost") is not None: + set_hidden_param(response, "additional_headers", {"llm_provider-x-litellm-response-cost": reported}) billed_at: Final = TypeAdapter(datetime).validate_python(logged.get("current_billing_time", event.ended_at)) if event.call_type is CallTypes.arealtime and captured.usage and captured.usage.get("metered_usage") is not None: from litellm.constants import REALTIME_METERED_USAGE_KEY diff --git a/tests/unit/proxy/spend_tracking/test_cost_compiler.py b/tests/unit/proxy/spend_tracking/test_cost_compiler.py index fe4e8ca7791..c54f5bc7039 100644 --- a/tests/unit/proxy/spend_tracking/test_cost_compiler.py +++ b/tests/unit/proxy/spend_tracking/test_cost_compiler.py @@ -936,6 +936,7 @@ async def test_capture_retains_provider_header_price_without_catalog(amount: flo result: Final = price_usage(database.rows[-1].envelope) assert isinstance(result, PricingSnapshot) assert result.total_cost == Decimal(str(amount)) + assert (result.input_cost or Decimal(0)) + (result.output_cost or Decimal(0)) == result.total_cost assert result.pricing_source == "upstream_header" finally: await meter.stop(1)