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:
devin-ai-integration[bot] 2026-10-25 02:20:53 +00:00
parent c200c2f9f8
commit b4ee6ef4f3
2 changed files with 2 additions and 4 deletions

View file

@ -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,

View file

@ -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