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]

Enrich rate limit error message with specific limit type and reset time (#14736)

Ishaan Jaffc918e18852b0
diff --git a/litellm/proxy/hooks/parallel_request_limiter_v3.py b/litellm/proxy/hooks/parallel_request_limiter_v3.py
index 87f4236b5aa..8ef0a662ffe 100644
--- a/litellm/proxy/hooks/parallel_request_limiter_v3.py
+++ b/litellm/proxy/hooks/parallel_request_limiter_v3.py
@@ -565,13 +565,34 @@ class _PROXY_MaxParallelRequestsHandler_v3(CustomLogger):
for i, status in enumerate(response["statuses"]):
if status["code"] == "OVER_LIMIT":
descriptor = descriptors[floor(i / 2)]
+
+ # Calculate reset time (window_start + window_size)
+ now = datetime.now().timestamp()
+ reset_time = now + self.window_size # Conservative estimate
+ reset_time_formatted = datetime.fromtimestamp(reset_time).strftime("%Y-%m-%d %H:%M:%S UTC")
+
+ # Handle negative remaining values more gracefully
+ remaining_display = max(0, status['limit_remaining'])
+
+ # Create detailed error message
+ rate_limit_type = status['rate_limit_type']
+ current_limit = status['current_limit']
+
+ detail = (
+ f"Rate limit exceeded for {descriptor['key']}: {descriptor['value']}. "
+ f"Limit type: {rate_limit_type}. "
+ f"Current limit: {current_limit}, Remaining: {remaining_display}. "
+ f"Limit resets at: {reset_time_formatted}"
+ )
+
raise HTTPException(
status_code=429,
- detail=f"Rate limit exceeded for {descriptor['key']}: {descriptor['value']}. Remaining: {status['limit_remaining']}",
+ detail=detail,
headers={
"retry-after": str(self.window_size),
"rate_limit_type": str(status["rate_limit_type"]),
- }, # Retry after 1 minute
+ "reset_at": reset_time_formatted,
+ },
)
else: