diff --git a/litellm/proxy/management_endpoints/cost_tracking_settings.py b/litellm/proxy/management_endpoints/cost_tracking_settings.py index a679e79f8d4..dc0da63555f 100644 --- a/litellm/proxy/management_endpoints/cost_tracking_settings.py +++ b/litellm/proxy/management_endpoints/cost_tracking_settings.py @@ -634,6 +634,7 @@ async def estimate_cost( # Pinning one moment keeps an off-peak window that opens mid-quote from pricing the totals on # one side of it and the reported rates on the other. with pinned_billing_time(current_billing_time()): + # Use completion_cost which handles all the logic including margins/discounts try: cost_per_request: Final = completion_cost( completion_response=mock_response, diff --git a/litellm/responses/streaming_iterator.py b/litellm/responses/streaming_iterator.py index a8dd8c2d8cd..40ff88fc557 100644 --- a/litellm/responses/streaming_iterator.py +++ b/litellm/responses/streaming_iterator.py @@ -1323,7 +1323,7 @@ def _stamp_responses_usage_cost( if usage_obj is None: return response_obj.usage = usage_obj # rebind-ok: the stamped cost has to ride on the response the client receives - if isinstance(usage_obj.cost, (int, float)): + if isinstance(getattr(usage_obj, "cost", None), (int, float)): return try: cost: Final[float | None] = logging_obj._response_cost_calculator(result=response_obj)