mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-12 08:42:18 +00:00
fix(accounting): replay provider headers through shared pricing
This commit is contained in:
parent
da08f7c269
commit
634bc134f5
2 changed files with 4 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue