BerriAI/litellm · error · ContextWindowExceededError

AI21Exception - {original_exception.message}

Error message

AI21Exception - {original_exception.message}

What it means

Error "AI21Exception - {original_exception.message}" thrown in BerriAI/litellm.

Source

Thrown at litellm/litellm_core_utils/exception_mapping_utils.py:1505

                llm_provider="huggingface",
                model=model,
                request=getattr(original_exception, "request", None),
            )


def _map_ai21_exception(
    *,
    model: str,
    original_exception: _ProviderHTTPException,
    custom_llm_provider: str,
    error_str: str,
    exception_type: str,
    exception_provider: str,
    extra_information: str,
) -> None:
    if hasattr(original_exception, "message"):
        if "Prompt has too many tokens" in original_exception.message:
            raise ContextWindowExceededError(
                message=f"AI21Exception - {original_exception.message}",
                model=model,
                llm_provider="ai21",
                response=getattr(original_exception, "response", None),
            )
        if "Bad or missing API token." in original_exception.message:
            raise BadRequestError(
                message=f"AI21Exception - {original_exception.message}",
                model=model,
                llm_provider="ai21",
                response=getattr(original_exception, "response", None),
            )
    if hasattr(original_exception, "status_code"):
        if original_exception.status_code == 401:
            raise AuthenticationError(
                message=f"AI21Exception - {original_exception.message}",
                llm_provider="ai21",
                model=model,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Inspect the AI21 error message; check model and inputs.

When it happens

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

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/48ecfeb39a953ec7. Report an issue: GitHub.