BerriAI/litellm · error · ContextWindowExceededError
ContextWindowExceededError
Error message
ContextWindowExceededError: {exception_provider} - {message} What it means
Exception-mapping branch: when the provider error string matches context-window-exceeded heuristics, the original exception is re-raised as litellm ContextWindowExceededError, signaling the request (prompt + max_tokens) exceeds the model's context length.
Solutions
- The input exceeds the model's context window; shorten the prompt/messages.
- Switch to a model with a larger context window or enable truncation/summarization.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/litellm_core_utils/exception_mapping_utils.py:298 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/b40a8a4f46dbeb49.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/exception_mapping_utils.py:298
"openai.OpenAIError",
f"{custom_llm_provider}.{custom_llm_provider}Error",
)
if custom_llm_provider == "openai":
exception_provider = "OpenAI" + "Exception"
else:
exception_provider = custom_llm_provider[0].upper() + custom_llm_provider[1:] + "Exception"
if ExceptionCheckers.is_error_str_rate_limit(
error_str, status_code=getattr(original_exception, "status_code", None)
):
raise RateLimitError(
message=f"RateLimitError: {exception_provider} - {message}",
model=model,
llm_provider=custom_llm_provider,
response=getattr(original_exception, "response", None),
)
elif ExceptionCheckers.is_error_str_context_window_exceeded(error_str):
raise ContextWindowExceededError(
message=f"ContextWindowExceededError: {exception_provider} - {message}",
llm_provider=custom_llm_provider,
model=model,
response=getattr(original_exception, "response", None),
litellm_debug_info=extra_information,
)
elif "invalid_request_error" in error_str and "model_not_found" in error_str:
raise NotFoundError(
message=f"{exception_provider} - {message}",
llm_provider=custom_llm_provider,
model=model,
response=getattr(original_exception, "response", None),
litellm_debug_info=extra_information,
)
elif "A timeout occurred" in error_str:
raise Timeout(
message=f"{exception_provider} - {message}",
model=model,View on GitHub (pinned to 77b7c6c40c)