BerriAI/litellm · error · ContextWindowExceededError

AnthropicError

Error message

AnthropicError - {error_str}

What it means

Anthropic-specific mapping: prompt-length errors ('prompt is too long', 'prompt: length') from the Anthropic SDK are re-raised as litellm ContextWindowExceededError, meaning the prompt exceeds Anthropic's context limit.

Solutions

  1. Check the Anthropic request parameters and API key against the error details.
  2. Verify the model name is a valid Anthropic model.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/litellm_core_utils/exception_mapping_utils.py:516 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/9e286ac2fb7e4b9c. Report an issue: GitHub.

Appendix: source

Thrown at litellm/litellm_core_utils/exception_mapping_utils.py:516

        )


def _map_anthropic_exception(
    *,
    model: str,
    original_exception: _ProviderHTTPException,
    custom_llm_provider: str,
    error_str: str,
    exception_type: str,
    exception_provider: str,
    extra_information: str,
) -> None:
    if (
        "prompt is too long" in error_str
        or "prompt: length" in error_str
        or ExceptionCheckers.is_error_str_context_window_exceeded(error_str)
    ):
        raise ContextWindowExceededError(
            message=f"AnthropicError - {error_str}",
            model=model,
            llm_provider="anthropic",
        )
    elif "overloaded_error" in error_str or "Overloaded" in error_str:
        raise InternalServerError(
            message=f"AnthropicError - {error_str}",
            model=model,
            llm_provider="anthropic",
        )
    if "Invalid API Key" in error_str:
        raise AuthenticationError(
            message=f"AnthropicError - {error_str}",
            model=model,
            llm_provider="anthropic",
        )
    if "content filtering policy" in error_str:
        raise ContentPolicyViolationError(

View on GitHub (pinned to 77b7c6c40c)