mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-05 08:07:05 +00:00
fix: attribute realtime transcription cost in cost breakdown
Pass transcription_cost through additional_costs so cost_breakdown's input_cost + output_cost + additional_costs sums to total_cost instead of silently folding it into total_cost only. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
8edfaa9bac
commit
f0d41e4d16
2 changed files with 13 additions and 0 deletions
|
|
@ -2356,6 +2356,7 @@ def handle_realtime_stream_cost_calculation(
|
|||
completion_tokens_cost_usd_dollar=output_cost_per_token,
|
||||
cost_for_built_in_tools_cost_usd_dollar=0.0,
|
||||
total_cost_usd_dollar=total_cost,
|
||||
additional_costs={"transcription_cost": transcription_cost} if transcription_cost > 0 else None,
|
||||
)
|
||||
|
||||
return total_cost
|
||||
|
|
|
|||
|
|
@ -695,6 +695,18 @@ def test_realtime_transcription_duration_cost(monkeypatch):
|
|||
assert logging_obj.cost_breakdown is not None
|
||||
assert abs(logging_obj.cost_breakdown["total_cost"] - cost) < 1e-9
|
||||
|
||||
# The transcription cost must be attributed in the breakdown, not just folded
|
||||
# into total_cost, or input_cost + output_cost + additional_costs won't sum to total_cost.
|
||||
additional_costs = logging_obj.cost_breakdown.get("additional_costs")
|
||||
assert additional_costs is not None
|
||||
assert abs(additional_costs["transcription_cost"] - expected) < 1e-9
|
||||
attributed_total = (
|
||||
logging_obj.cost_breakdown["input_cost"]
|
||||
+ logging_obj.cost_breakdown["output_cost"]
|
||||
+ additional_costs["transcription_cost"]
|
||||
)
|
||||
assert abs(attributed_total - logging_obj.cost_breakdown["total_cost"]) < 1e-9
|
||||
|
||||
|
||||
def test_realtime_transcription_duration_cost_resolves_model_from_litellm_name(
|
||||
monkeypatch,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue