BerriAI/litellm · error · MidStreamFallbackError
str(mapped_exception)
Error message
str(mapped_exception)
What it means
Router streaming fallback decision point: when a mid-stream exception occurs, the mapped exception's string is raised if the error is judged non-transient (e.g. client errors other than 429); the string form of the mapped exception becomes the surfaced error for the failing stream.
Source
Thrown at litellm/litellm_core_utils/streaming_handler.py:2381
status_code: Final[int | str | None] = getattr(response, "status_code", None)
if status_code is not None:
return int(status_code)
except Exception:
pass
return None
mapped_status_code: Final = _normalize_status_code(mapped_exception)
original_status_code: Final = _normalize_status_code(e)
# Raise non-retriable client errors directly (skip fallback).
# Exception: 429 (rate-limit) IS retriable/transient — allow it
# through so the Router can switch to a different model group.
if mapped_status_code is not None and 400 <= mapped_status_code < 500 and mapped_status_code != 429:
raise mapped_exception
if original_status_code is not None and 400 <= original_status_code < 500 and original_status_code != 429:
raise mapped_exception
raise MidStreamFallbackError(
message=str(mapped_exception),
model=self.model,
llm_provider=self.custom_llm_provider or "anthropic",
original_exception=mapped_exception,
generated_content=self.response_uptil_now,
is_pre_first_chunk=not self.sent_first_chunk,
)
@staticmethod
def _strip_sse_data_from_chunk(chunk: str | None) -> str | None:
"""
Strips the 'data: ' prefix from Server-Sent Events (SSE) chunks.
Some providers like sagemaker send it as `data:`, need to handle both
SSE messages are prefixed with 'data: ' which is part of the protocol,
not the actual content from the LLM. This method removes that prefix
and returns the actual content.View on GitHub (pinned to 77b7c6c40c)
Solutions
- Inspect the mapped exception (str(mapped_exception)) with verbose logging for the root cause.
- Fix the underlying request or configuration issue that produced the exception.
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at litellm/litellm_core_utils/streaming_handler.py:2381 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/b0b090ac01d49c03.
Report an issue: GitHub.