refactor(proxy/hooks): raise ProxyRateLimitError from batch rate limiter

Replaces HTTPException(status_code=429, ...) in batch_rate_limiter._raise_rate_limit_error
with ProxyRateLimitError tagged as RateLimitErrorCategory.LITELLM_BATCH_RATE_LIMIT
so users can distinguish batch-level throttling (which counts requests/tokens
across an uploaded batch input file before submission) from the generic
key/team/user RPM/TPM limiter.

The HTTPException import is retained because the same module raises
HTTPException for unrelated 403/IO error paths.

LIT-2968

Co-authored-by: Mateo Wang <mateo-berri@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-05-11 22:43:44 +00:00
parent be5b496ad8
commit f74c9f19b3
No known key found for this signature in database

View file

@ -29,8 +29,10 @@ from litellm.batches.batch_utils import (
_get_file_content_as_dictionary,
_get_models_from_batch_input_file_content,
)
from litellm.exceptions import RateLimitErrorCategory
from litellm.integrations.custom_logger import CustomLogger
from litellm.proxy._types import UserAPIKeyAuth
from litellm.proxy.common_utils.proxy_rate_limit_error import ProxyRateLimitError
if TYPE_CHECKING:
from opentelemetry.trace import Span as _Span
@ -105,7 +107,7 @@ class _PROXY_BatchRateLimiter(CustomLogger):
batch_usage: BatchFileUsage,
limit_type: str,
) -> None:
"""Raise HTTPException for rate limit exceeded."""
"""Raise :class:`ProxyRateLimitError` (a 429) for batch rate limit exceeded."""
from datetime import datetime
# Find the descriptor for this status
@ -148,14 +150,14 @@ class _PROXY_BatchRateLimiter(CustomLogger):
f"Limit resets at: {reset_time_formatted}"
)
raise HTTPException(
status_code=429,
raise ProxyRateLimitError(
detail=detail,
headers={
"retry-after": str(window_size),
"rate_limit_type": limit_type,
"reset_at": reset_time_formatted,
},
category=RateLimitErrorCategory.LITELLM_BATCH_RATE_LIMIT,
)
async def _check_and_increment_batch_counters(