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(proxy): tolerate non-scalar sse keepalive interval config shapes

mateo-berri097c03eebb94
diff --git a/litellm/proxy/common_utils/sse_keepalive.py b/litellm/proxy/common_utils/sse_keepalive.py
index e6d5da03a71..6700700ff7c 100644
--- a/litellm/proxy/common_utils/sse_keepalive.py
+++ b/litellm/proxy/common_utils/sse_keepalive.py
@@ -14,7 +14,7 @@ def _coerce_interval(ping_interval_seconds: float | str | None) -> float | None:
return None
try:
interval: Final = float(ping_interval_seconds)
- except ValueError:
+ except (TypeError, ValueError):
return None
if not math.isfinite(interval) or interval <= 0:
return None
diff --git a/tests/test_litellm/proxy/common_utils/test_sse_keepalive.py b/tests/test_litellm/proxy/common_utils/test_sse_keepalive.py
index 6e98248dd18..9cca9bbfe12 100644
--- a/tests/test_litellm/proxy/common_utils/test_sse_keepalive.py
+++ b/tests/test_litellm/proxy/common_utils/test_sse_keepalive.py
@@ -1,6 +1,6 @@
import asyncio
from collections.abc import AsyncGenerator
-from typing import Final
+from typing import Final, cast
import pytest
from fastapi.responses import StreamingResponse
@@ -105,7 +105,19 @@ async def test_non_positive_interval_returns_stream_unwrapped():
@pytest.mark.asyncio
[email protected]("bad_interval", [None, "abc", "", float("inf"), float("nan"), "-3"])
+ "bad_interval",
+ [
+ None,
+ "abc",
+ "",
+ float("inf"),
+ float("nan"),
+ "-3",
+ cast("float | str | None", [15]),
+ cast("float | str | None", {"seconds": 15}),
+ ],
+)
async def test_invalid_config_interval_returns_stream_unwrapped(bad_interval: float | str | None):
async def any_stream() -> AsyncGenerator[str, None]:
yield MESSAGE_START_CHUNK