diff --git a/litellm/litellm_core_utils/exception_mapping_utils.py b/litellm/litellm_core_utils/exception_mapping_utils.py index 70374f87b99..e9e946a4e0d 100644 --- a/litellm/litellm_core_utils/exception_mapping_utils.py +++ b/litellm/litellm_core_utils/exception_mapping_utils.py @@ -91,6 +91,7 @@ class ExceptionCheckers: "`inputs` tokens + `max_new_tokens` must be", "exceeds the available context size", # llama.cpp/Lemonade "exceeds the maximum number of tokens allowed", # Gemini + "prompt is too long", ] for substring in known_exception_substrings: if substring in _error_str_lowercase: 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 8e89180a9e4..430b22ca607 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 @@ -406,6 +406,24 @@ def test_anthropic_context_window_error_mapping(error_message): assert excinfo.value.llm_provider == "anthropic" +def test_vertex_ai_anthropic_context_window_error_mapping(): + error_message = ( + '{"type":"error","error":{"type":"invalid_request_error",' + '"message":"prompt is too long: 1000423 tokens > 1000000 maximum"}}' + ) + + with pytest.raises(litellm.ContextWindowExceededError) as excinfo: + exception_type( + model="claude-opus-5", + original_exception=Exception(error_message), + custom_llm_provider="vertex_ai", + ) + + assert excinfo.value.status_code == 400 + assert excinfo.value.llm_provider == "vertex_ai" + assert excinfo.value.model == "claude-opus-5" + + # Test cases for Vertex AI RateLimitError mapping # As per https://github.com/BerriAI/litellm/issues/16189 vertex_rate_limit_test_cases = [