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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(proxy): guard candidate-count and batch cap coercion against float overflow
mateo-berri3c34c344597b
diff --git a/litellm/proxy/hooks/batch_rate_limiter.py b/litellm/proxy/hooks/batch_rate_limiter.pyindex 404de776396..d6229fb80a6 100644--- a/litellm/proxy/hooks/batch_rate_limiter.py+++ b/litellm/proxy/hooks/batch_rate_limiter.py@@ -433,7 +433,7 @@ class _PROXY_BatchRateLimiter(CustomLogger):if explicit_cap is not None:try:return max(0, int(explicit_cap)) * candidate_count- except (TypeError, ValueError):+ except (TypeError, ValueError, OverflowError):passreturn self.parallel_request_limiter.no_max_tokens_output_floor(min_configured_otpm_limit) * candidate_countdiff --git a/litellm/proxy/hooks/parallel_request_limiter_v3.py b/litellm/proxy/hooks/parallel_request_limiter_v3.pyindex 4a8da065fcf..2d799ded752 100644--- a/litellm/proxy/hooks/parallel_request_limiter_v3.py+++ b/litellm/proxy/hooks/parallel_request_limiter_v3.py@@ -768,7 +768,7 @@ class _PROXY_MaxParallelRequestsHandler_v3(CustomLogger):for value in candidate_values:try:candidate_count = max(candidate_count, int(value or 1))- except (TypeError, ValueError):+ except (TypeError, ValueError, OverflowError):continuereturn candidate_countdiff --git a/tests/test_litellm/proxy/hooks/test_batch_file_validation.py b/tests/test_litellm/proxy/hooks/test_batch_file_validation.pyindex 31afb5c6019..1ce1a2f3e51 100644--- a/tests/test_litellm/proxy/hooks/test_batch_file_validation.py+++ b/tests/test_litellm/proxy/hooks/test_batch_file_validation.py@@ -2077,6 +2077,8 @@ def test_estimate_entry_output_tokens_prefers_max_tokens_over_max_output_tokens(({"max_tokens": 40, "n": 5.0}, 200),({"max_tokens": 40, "n": "10"}, 400),({"max_tokens": 40, "n": "not-a-number"}, 40),+ ({"max_tokens": 40, "n": 1e309}, 40),+ ({"max_tokens": 1e309, "n": 3}, 2997),({"n": 3}, 2997),],)diff --git a/tests/test_litellm/proxy/hooks/test_tpm_concurrent.py b/tests/test_litellm/proxy/hooks/test_tpm_concurrent.pyindex e08b18c1ae9..8d03857c917 100644--- a/tests/test_litellm/proxy/hooks/test_tpm_concurrent.py+++ b/tests/test_litellm/proxy/hooks/test_tpm_concurrent.py@@ -3385,6 +3385,7 @@ def test_split_quota_helpers_handle_non_mapping_inputs(rate_limiter):assert handler._is_embedding_request(object(), None) is Falseassert handler._get_explicit_output_cap(object(), None) is Noneassert handler.get_output_candidate_count(object()) == 1+ assert handler.get_output_candidate_count({"n": 1e309}) == 1assert (handler._get_explicit_output_cap({"max_output_tokens": []}, "responses") is None)