Skip to main content

is_context_window_exceeded

Function is_context_window_exceeded 

Source
pub fn is_context_window_exceeded(err: &Error) -> bool
Expand description

Return true when err looks like an LLM context-window-exceeded error.

OpenAI-compatible providers (GLM, DeepSeek, …) return HTTP 400 whose body contains an error code or human-readable message indicating the prompt is too long. We match several common patterns across providers:

ProviderTypical signal
OpenAI / NIM"context_length_exceeded" (error code)
OpenAI / NIM"maximum context length" (human message)
Some providers"context window"
DeepSeek"prompt is too long"
Some providers"tokens exceeds"

The function intentionally casts to lowercase before matching so it is resilient to capitalisation differences across providers.