Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_stream_usage_cost_default

mateo-berride0a4c1b0a3b
diff --cc litellm/responses/streaming_iterator.py
index 81db7e73da5,82abac3e772..7871c85220c
--- a/litellm/responses/streaming_iterator.py
+++ b/litellm/responses/streaming_iterator.py
@@@ -1258,28 -1274,10 +1258,28 @@@ def _add_text_like_part_events
)
+def _stamp_responses_usage_cost(
+ response_obj: ResponsesAPIResponse | None, logging_obj: LiteLLMLoggingObj | None
+) -> None:
+ if response_obj is None or logging_obj is None:
+ return
+ usage_obj: Final[ResponseAPIUsage | None] = getattr(response_obj, "usage", None)
+ if usage_obj is None:
+ return
+ if isinstance(getattr(usage_obj, "cost", None), (int, float)):
+ return
+ try:
+ cost: Final[float | None] = logging_obj._response_cost_calculator(result=response_obj)
+ except Exception:
+ return
+ if isinstance(cost, (int, float)) and cost > 0:
+ setattr(usage_obj, "cost", cost)
+
+
- def _build_synthetic_response_events(
+ def build_synthetic_response_events(
*,
transformed: ResponsesAPIResponse,
- logging_obj: LiteLLMLoggingObj,
+ logging_obj: LiteLLMLoggingObj | None,
chunk_size: int,
) -> list[ResponsesAPIStreamingResponse]:
openai_types: Final = _get_openai_response_types()