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]

fix redis serialization issue with Redis + lowest latency strategy

Emerson Gomes18c2592f2b21
diff --git a/litellm/router_strategy/lowest_latency.py b/litellm/router_strategy/lowest_latency.py
index b049c942642..0ec71116e29 100644
--- a/litellm/router_strategy/lowest_latency.py
+++ b/litellm/router_strategy/lowest_latency.py
@@ -124,7 +124,9 @@ class LowestLatencyLoggingHandler(CustomLogger):
len(request_count_dict[id].get("latency", []))
< self.routing_args.max_latency_list_size
):
- request_count_dict[id].setdefault("latency", []).append(final_value)
+ latency_value = final_value.total_seconds() if isinstance(final_value, timedelta) else final_value
+ request_count_dict[id].setdefault("latency", []).append(latency_value)
+
else:
request_count_dict[id]["latency"] = request_count_dict[id][
"latency"
@@ -332,7 +334,9 @@ class LowestLatencyLoggingHandler(CustomLogger):
len(request_count_dict[id].get("latency", []))
< self.routing_args.max_latency_list_size
):
- request_count_dict[id].setdefault("latency", []).append(final_value)
+ latency_value = final_value.total_seconds() if isinstance(final_value, timedelta) else final_value
+ request_count_dict[id].setdefault("latency", []).append(latency_value)
+
else:
request_count_dict[id]["latency"] = request_count_dict[id][
"latency"
@@ -465,6 +469,8 @@ class LowestLatencyLoggingHandler(CustomLogger):
total: float = 0.0
if (
request_kwargs is not None
+ and len(item_latency) > 0
+ and isinstance(item_latency[0], timedelta)
and request_kwargs.get("stream", None) is not None
and request_kwargs["stream"] is True
and len(item_ttft_latency) > 0
@@ -472,6 +478,9 @@ class LowestLatencyLoggingHandler(CustomLogger):
for _call_latency in item_ttft_latency:
if isinstance(_call_latency, float):
total += _call_latency
+ elif len(item_latency) > 0 and isinstance(item_latency[0], timedelta):
+ for _call_latency in item_latency:
+ total += _call_latency.total_seconds()
else:
for _call_latency in item_latency:
if isinstance(_call_latency, float):