BerriAI/litellm · error · ContextWindowExceededError
AlephAlphaException
Error message
AlephAlphaException - {original_exception.message} What it means
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.
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
Example fix
# before
litellm.completion(model='aleph_alpha/luminous-supreme', messages=full_history)
# after
limit = litellm.get_max_tokens('aleph_alpha/luminous-supreme')
while litellm.token_counter(model='aleph_alpha/luminous-supreme', messages=full_history) > limit - 256:
full_history.pop(1) # drop oldest turns, keep system message
litellm.completion(model='aleph_alpha/luminous-supreme', messages=full_history) Defensive patterns
Strategy: validation
Validate before calling
model = 'aleph_alpha/luminous-base'
limit = litellm.get_max_tokens(model)
if litellm.token_counter(model=model, messages=msgs) >= limit - 256:
msgs = trim_history(msgs, budget=limit - 256) # keep system message, drop oldest Type guard
def is_context_window_error(e: BaseException) -> bool:
return isinstance(e, litellm.ContextWindowExceededError) Try / catch
try:
resp = litellm.completion(model=model, messages=msgs)
except litellm.ContextWindowExceededError:
resp = litellm.completion(model=model, messages=summarize_then_trim(msgs)) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- AI21Exception
- Exception: Context Window Error
- ContextWindowExceededError
- TogetherAIException
- BedrockException: Context Window Error
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/82db2312393f3d7d.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/exception_mapping_utils.py:1748
message=f"TogetherAIException - {original_exception.message}",
llm_provider="together_ai",
model=model,
request=getattr(original_exception, "request", None),
)
def _map_aleph_alpha_exception(
*,
model: str,
original_exception: _ProviderHTTPException,
custom_llm_provider: str,
error_str: str,
exception_type: str,
exception_provider: str,
extra_information: str,
) -> None:
if "This is longer than the model's maximum context length" in error_str:
raise ContextWindowExceededError(
message=f"AlephAlphaException - {original_exception.message}",
llm_provider="aleph_alpha",
model=model,
response=getattr(original_exception, "response", None),
)
elif "InvalidToken" in error_str or "No token provided" in error_str:
raise BadRequestError(
message=f"AlephAlphaException - {original_exception.message}",
llm_provider="aleph_alpha",
model=model,
response=getattr(original_exception, "response", None),
)
elif hasattr(original_exception, "status_code"):
verbose_logger.debug("status code: %s", original_exception.status_code)
if original_exception.status_code == 401:
raise AuthenticationError(
message=f"AlephAlphaException - {original_exception.message}",
llm_provider="aleph_alpha",View on GitHub (pinned to 77b7c6c40c)