BerriAI/litellm · error · ValueError

Bad response code, expected 200: {response_dict}

Error message

Bad response code, expected 200: {response_dict}

What it means

Response guard in the SageMaker event-stream decoder: an invocation response arrived whose status/payload is not a 200-style success, and the accumulated response_dict is echoed so the caller can see what the endpoint returned.

Source

Thrown at litellm/llms/sagemaker/common_utils.py:207

                yield None
            except Exception as e:
                verbose_logger.error("Final error parsing accumulated JSON: %s", e)

    def _parse_message_from_event(self, event) -> str | None:
        response_stream_shape: Final = get_sagemaker_response_stream_shape()
        if response_stream_shape is None:
            raise SagemakerError(
                status_code=500,
                message=(
                    "SageMaker event-stream shape could not be loaded from botocore. "
                    "Ensure botocore is correctly installed."
                ),
            )
        response_dict: Final = event.to_response_dict()
        parsed_response: Final = self.parser.parse(response_dict, response_stream_shape)

        if response_dict["status_code"] != 200:
            raise ValueError(f"Bad response code, expected 200: {response_dict}")

        if "chunk" in parsed_response:
            chunk = parsed_response.get("chunk")
            if not chunk:
                return None
            return chunk.get("bytes").decode()
        else:
            chunk = response_dict.get("body")
            if not chunk:
                return None

            return chunk.decode()

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. The SageMaker endpoint returned a non-200 code; inspect response_dict for details.
  2. Check endpoint health and request payload.

Example fix

# log response_dict and check the endpoint in the AWS console.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Triggered when the SageMaker endpoint returns a response code other than 200.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/3bf7e267d39cae2f. Report an issue: GitHub.