mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-11 08:38:24 +00:00
fix(cost): stamp the billed cost over a reported usage.cost on streams
The final streamed usage.cost a client sees is what the proxy billed, so an operator priced deployment shows its own rates instead of the upstream's number. Types region_name on cost_per_token.
This commit is contained in:
parent
c200c2f9f8
commit
b4ee6ef4f3
2 changed files with 2 additions and 4 deletions
|
|
@ -427,7 +427,7 @@ def cost_per_token(
|
|||
completion_tokens: int = 0,
|
||||
response_time_ms: float | None = 0.0,
|
||||
custom_llm_provider: str | None = None,
|
||||
region_name=None,
|
||||
region_name: str | None = None,
|
||||
### CHARACTER PRICING ###
|
||||
prompt_characters: int | None = None,
|
||||
completion_characters: int | None = None,
|
||||
|
|
@ -508,7 +508,7 @@ def _cost_per_token_from_rates(
|
|||
completion_tokens: int = 0,
|
||||
response_time_ms: float | None = 0.0,
|
||||
custom_llm_provider: str | None = None,
|
||||
region_name=None,
|
||||
region_name: str | None = None,
|
||||
### CHARACTER PRICING ###
|
||||
prompt_characters: int | None = None,
|
||||
completion_characters: int | None = None,
|
||||
|
|
|
|||
|
|
@ -1413,8 +1413,6 @@ def _set_stream_builder_response_cost(
|
|||
def _stamp_streaming_usage_cost(usage: Usage, response: ModelResponse, logging_obj: Optional["Logging"]) -> None:
|
||||
if logging_obj is None:
|
||||
return
|
||||
if isinstance(getattr(usage, "cost", None), (int, float)):
|
||||
return
|
||||
computed_cost: Final = logging_obj.response_cost_calculator(result=response)
|
||||
if not isinstance(computed_cost, (int, float)) or computed_cost <= 0:
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue