{"record":{"id":"82db2312393f3d7d","repo":"BerriAI/litellm","slug":"alephalphaexception-original-exception-message","errorCode":null,"errorMessage":"AlephAlphaException - {original_exception.message}","messagePattern":"AlephAlphaException - (.+?)","errorType":"exception","errorClass":"ContextWindowExceededError","httpStatus":400,"severity":"error","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":1748,"sourceCode":"            message=f\"TogetherAIException - {original_exception.message}\",\n            llm_provider=\"together_ai\",\n            model=model,\n            request=getattr(original_exception, \"request\", None),\n        )\n\n\ndef _map_aleph_alpha_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 \"This is longer than the model's maximum context length\" in error_str:\n        raise ContextWindowExceededError(\n            message=f\"AlephAlphaException - {original_exception.message}\",\n            llm_provider=\"aleph_alpha\",\n            model=model,\n            response=getattr(original_exception, \"response\", None),\n        )\n    elif \"InvalidToken\" in error_str or \"No token provided\" in error_str:\n        raise BadRequestError(\n            message=f\"AlephAlphaException - {original_exception.message}\",\n            llm_provider=\"aleph_alpha\",\n            model=model,\n            response=getattr(original_exception, \"response\", None),\n        )\n    elif hasattr(original_exception, \"status_code\"):\n        verbose_logger.debug(\"status code: %s\", original_exception.status_code)\n        if original_exception.status_code == 401:\n            raise AuthenticationError(\n                message=f\"AlephAlphaException - {original_exception.message}\",\n                llm_provider=\"aleph_alpha\",","sourceCodeStart":1730,"sourceCodeEnd":1766,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/exception_mapping_utils.py#L1730-L1766","documentation":"litellm raises litellm.ContextWindowExceededError when an Aleph Alpha error contains 'This is longer than the model's maximum context length'. The combined prompt (and requested completion) overflow the model's context window.","triggerScenarios":"Calling model='aleph_alpha/...' with a prompt whose token count plus max_tokens exceeds the model's context limit (e.g. Luminous models); Aleph Alpha returns the context-length error and this mapper converts it.","commonSituations":"Stuffing long documents into a prompt without token counting; switching from a large-context model to Luminous without resizing inputs; inheriting conversation histories that grow unboundedly.","solutions":["Trim or summarize the input to fit the model's context window","Switch to a model/deployment with a larger context window","Count tokens with litellm.token_counter before the call and drop oldest turns","Chunk long documents and aggregate answers instead of one giant prompt"],"exampleFix":"# before\nlitellm.completion(model='aleph_alpha/luminous-supreme', messages=entire_history)\n# after\nbudget = litellm.get_max_tokens('aleph_alpha/luminous-supreme') or 2048\nmsgs = trim_to_budget(entire_history, budget - 512)\nlitellm.completion(model='aleph_alpha/luminous-supreme', messages=msgs, max_tokens=512)","handlingStrategy":"validation","validationCode":"used = litellm.token_counter(model='aleph_alpha/luminous-supreme', messages=msgs) + max_tokens\nlimit = litellm.get_max_tokens('aleph_alpha/luminous-supreme') or 2048\nif used > limit:\n    msgs = trim_messages(msgs, limit - max_tokens - 64)","typeGuard":"import litellm\n\ndef is_context_overflow(e: Exception) -> bool:\n    return isinstance(e, litellm.ContextWindowExceededError)","tryCatchPattern":"try:\n    litellm.completion(...)\nexcept litellm.ContextWindowExceededError:\n    msgs = trim_to_budget(msgs)\n    return litellm.completion(..., messages=msgs)  # one retry, smaller","preventionTips":["Pre-count tokens on every aleph_alpha call","Cap stored conversation turns","Store per-model context limits and validate against them in CI"],"tags":["aleph-alpha","context-window","validation","litellm"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}