8 views
-/https://github.com/berriai/litellm/issues/28063
GitHub · issue

#28063 OpenRouter 400s with context-window errors get raised as BadRequestError, not ContextWindowExceededError

  • State: open
  • Author: @larstalian
  • Labels: llm translation

OpenRouter passes upstream context-window errors through with status 400 — e.g. OpenAI-style "maximum context length is X tokens" or Anthropic-style "input length exceeds the maximum". For every other provider in `exception_mapping_utils.py`, a 400 whose `error_str` matches the canonical context-window phrases gets raised as `ContextWindowExceededError`. The OpenRouter branch skips that check and always raises plain `BadRequestError`.

Concretely, in `litellm/litellm_core_utils/exception_mapping_utils.py` (line ~2316 on `main`):

```python if custom_llm_provider == "openrouter": if hasattr(original_exception, "status_code"): exception_mapping_worked = True if original_exception.status_code == 400: exception_mapping_worked = True raise BadRequestError(...) # <-- unconditional ```

Other branches (e.g. line ~398) do this first:

```python elif ExceptionCheckers.is_error_str_context_window_exceeded(error_str): raise ContextWindowExceededError(...) ```

The downstream effect: consumers can't distinguish "real bad request" from "context overflow", so SDKs that have a context-window recovery path (auto-compaction, sliding window, fal…

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (1 events)
#0 of 0 · 31d18h3m32s ago — entered · #import:https:::github.com:berriai:litellm post #2792
#28063 requires changes to shared exception-mapping control flow, careful provider-specific behavior validation, and regression tests across error classifications. #32650 is primarily a scoped pricing-data/configuration update with comparatively limited code-path risk.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search