diff --git a/litellm/litellm_core_utils/exception_mapping_utils.py b/litellm/litellm_core_utils/exception_mapping_utils.py index 056522e2a6..97f62fed81 100644 --- a/litellm/litellm_core_utils/exception_mapping_utils.py +++ b/litellm/litellm_core_utils/exception_mapping_utils.py @@ -82,6 +82,14 @@ class ExceptionCheckers: for substring in known_exception_substrings: if substring in _error_str_lowercase: return True + + # Cerebras pattern: "Current length is X while limit is Y" + if ( + "current length is" in _error_str_lowercase + and "while limit is" in _error_str_lowercase + ): + return True + return False @staticmethod diff --git a/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py b/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py index d59e52d965..8852e9d5ac 100644 --- a/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py +++ b/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py @@ -42,6 +42,16 @@ context_window_test_cases = [ ), # Test case insensitivity ("ERROR: THIS MODEL'S MAXIMUM CONTEXT LENGTH IS 1024.", True), + # Cerebras context window error format + # See: https://github.com/BerriAI/litellm/issues/XXXX + ( + "Current length is 132784 while limit is 131000", + True, + ), + ( + "CerebrasException - Please reduce the length of the messages or completion. Current length is 50000 while limit is 40000", + True, + ), # Negative cases (should return False) ("A generic API error occurred.", False), ("Invalid API Key provided.", False),