mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-04 02:31:27 +00:00
feat(logging): expose rate-limit category via StandardLoggingPayload
Adds an optional 'error_rate_limit_category' field to StandardLoggingPayloadErrorInformation, populated from the unified RateLimitError.category attribute (introduced in the previous commits on this branch). Why: the .category attribute is reachable off the raw exception today via getattr(e, 'category', None), but the structured contract that downstream custom callbacks / loggers / spend log writers consume is the StandardLoggingPayload. Without this field, a user building custom rate-limit metrics on top of callback data has to special-case the raw exception object — which defeats the purpose of the StandardLoggingPayload abstraction. The field is None for non-rate-limit exceptions (so consumers can read it unconditionally without isinstance checks) and is one of the RateLimitErrorCategory string values otherwise. LIT-2968 Co-authored-by: Mateo Wang <mateo-berri@users.noreply.github.com>
This commit is contained in:
parent
8f7bdf567a
commit
5f9ab59957
2 changed files with 21 additions and 0 deletions
|
|
@ -5159,12 +5159,23 @@ class StandardLoggingPayloadSetup:
|
|||
# Get additional error details
|
||||
error_message = str(original_exception)
|
||||
|
||||
# For rate-limit errors (litellm.RateLimitError + the proxy-side
|
||||
# ProxyRateLimitError subclass), surface the unified `category` field
|
||||
# so callbacks can distinguish vendor vs. litellm rate limits without
|
||||
# reaching for the raw exception object.
|
||||
rate_limit_category: Optional[str] = (
|
||||
getattr(original_exception, "category", None)
|
||||
if original_exception is not None
|
||||
else None
|
||||
)
|
||||
|
||||
return StandardLoggingPayloadErrorInformation(
|
||||
error_code=error_status,
|
||||
error_class=error_class,
|
||||
llm_provider=_llm_provider_in_exception,
|
||||
traceback=traceback_info,
|
||||
error_message=error_message if original_exception else "",
|
||||
error_rate_limit_category=rate_limit_category,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
|
|
@ -2697,6 +2697,16 @@ class StandardLoggingPayloadErrorInformation(TypedDict, total=False):
|
|||
llm_provider: Optional[str]
|
||||
traceback: Optional[str]
|
||||
error_message: Optional[str]
|
||||
error_rate_limit_category: Optional[str]
|
||||
"""
|
||||
For 429 / rate-limit errors, the source of the rate limit. One of the
|
||||
string values defined by :class:`litellm.exceptions.RateLimitErrorCategory`
|
||||
(``vendor_rate_limit``, ``vendor_batch_rate_limit``, ``litellm_rate_limit``,
|
||||
``litellm_batch_rate_limit``). ``None`` for non-rate-limit exceptions.
|
||||
|
||||
Surfaced here so custom callbacks / metrics consumers can switch on the
|
||||
rate-limit source without reaching for the raw exception.
|
||||
"""
|
||||
|
||||
|
||||
class GuardrailMode(TypedDict, total=False):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue