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]

Fix Cerebras context window errors not recognized (#17587)

Earl St Sauverad9c69860eaa
diff --git a/litellm/litellm_core_utils/exception_mapping_utils.py b/litellm/litellm_core_utils/exception_mapping_utils.py
index 056522e2a64..97f62fed81a 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 d59e52d965e..8852e9d5ac6 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),