{"record":{"id":"48ecfeb39a953ec7","repo":"BerriAI/litellm","slug":"ai21exception-original-exception-message","errorCode":null,"errorMessage":"AI21Exception - {original_exception.message}","messagePattern":"AI21Exception - (.+?)","errorType":"exception","errorClass":"ContextWindowExceededError","httpStatus":400,"severity":"error","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":1505,"sourceCode":"                llm_provider=\"huggingface\",\n                model=model,\n                request=getattr(original_exception, \"request\", None),\n            )\n\n\ndef _map_ai21_exception(\n    *,\n    model: str,\n    original_exception: _ProviderHTTPException,\n    custom_llm_provider: str,\n    error_str: str,\n    exception_type: str,\n    exception_provider: str,\n    extra_information: str,\n) -> None:\n    if hasattr(original_exception, \"message\"):\n        if \"Prompt has too many tokens\" in original_exception.message:\n            raise ContextWindowExceededError(\n                message=f\"AI21Exception - {original_exception.message}\",\n                model=model,\n                llm_provider=\"ai21\",\n                response=getattr(original_exception, \"response\", None),\n            )\n        if \"Bad or missing API token.\" in original_exception.message:\n            raise BadRequestError(\n                message=f\"AI21Exception - {original_exception.message}\",\n                model=model,\n                llm_provider=\"ai21\",\n                response=getattr(original_exception, \"response\", None),\n            )\n    if hasattr(original_exception, \"status_code\"):\n        if original_exception.status_code == 401:\n            raise AuthenticationError(\n                message=f\"AI21Exception - {original_exception.message}\",\n                llm_provider=\"ai21\",\n                model=model,","sourceCodeStart":1487,"sourceCodeEnd":1523,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/exception_mapping_utils.py#L1487-L1523","documentation":"Error \"AI21Exception - {original_exception.message}\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/litellm_core_utils/exception_mapping_utils.py:1505 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the AI21 error message; check model and inputs."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}