{"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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/exception_mapping_utils.py#L1730-L1766","documentation":"When Aleph Alpha's error text contains \"This is longer than the model's maximum context length\", litellm raises ContextWindowExceededError (BadRequestError subclass). Your prompt alone exceeded the served model's context — this mapping fires on the error string, before any status-code handling.","triggerScenarios":"completion calls on model='aleph_alpha/<luminous-model>' where the prompt tokens exceed the model's context limit: whole documents pasted as input, accumulated conversation history, or large few-shot prefixes.","commonSituations":"Long chat histories never truncated; RAG retrieval returning more chunks than the model holds; test prompts sized for larger-context models reused on luminous-base.","solutions":["Trim or summarize the prompt below the model's context limit","Pre-flight with litellm.token_counter(model, messages) compared to litellm.get_max_tokens(model)","Keep a sliding window over conversation history instead of replaying it fully","Move to a provider/model with a larger context if prompts are legitimately big"],"exampleFix":"# before\nlitellm.completion(model='aleph_alpha/luminous-supreme', messages=full_history)\n\n# after\nlimit = litellm.get_max_tokens('aleph_alpha/luminous-supreme')\nwhile litellm.token_counter(model='aleph_alpha/luminous-supreme', messages=full_history) > limit - 256:\n    full_history.pop(1)  # drop oldest turns, keep system message\nlitellm.completion(model='aleph_alpha/luminous-supreme', messages=full_history)","handlingStrategy":"validation","validationCode":"model = 'aleph_alpha/luminous-base'\nlimit = litellm.get_max_tokens(model)\nif litellm.token_counter(model=model, messages=msgs) >= limit - 256:\n    msgs = trim_history(msgs, budget=limit - 256)  # keep system message, drop oldest","typeGuard":"def is_context_window_error(e: BaseException) -> bool:\n    return isinstance(e, litellm.ContextWindowExceededError)","tryCatchPattern":"try:\n    resp = litellm.completion(model=model, messages=msgs)\nexcept litellm.ContextWindowExceededError:\n    resp = litellm.completion(model=model, messages=summarize_then_trim(msgs))","preventionTips":["Pre-count prompt tokens and trim before the call, not after the failure","Use a sliding window on conversation history","Know each model's context limit; do not assume one size fits all"],"tags":["aleph-alpha","litellm","context-window","token-limit","prompt-too-long"],"backgroundTag":"context-window-exceeded","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}