BerriAI/litellm · critical · BedrockError

Bedrock event-stream shape could not be loaded from botocore

Error message

Bedrock event-stream shape could not be loaded from botocore. Ensure botocore is correctly installed.

What it means

Raised inside AWSEventStreamDecoder._parse_message_from_event when get_bedrock_response_stream_shape() returns None, i.e. litellm could not load the 'responseStream' event-stream shape from the installed botocore's Bedrock service model. Because decoding the AWS binary event-stream format depends on that shape, parsing cannot proceed and a BedrockError 500 with the fixed message is raised.

Source

Thrown at litellm/llms/bedrock/chat/invoke_handler.py:678

                    yield self._chunk_parser(chunk_data=_data)

    async def aiter_bytes(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[GChunk | ModelResponseStream | dict]:
        """Given an async iterator that yields lines, iterate over it & yield every event encountered"""
        from botocore.eventstream import EventStreamBuffer

        event_stream_buffer: Final = EventStreamBuffer()
        async for chunk in iterator:
            event_stream_buffer.add_data(chunk)
            for event in event_stream_buffer:
                message = self._parse_message_from_event(event)
                if message:
                    _data = json.loads(message)
                    yield self._chunk_parser(chunk_data=_data)

    def _parse_message_from_event(self, event) -> str | None:
        response_stream_shape: Final = get_bedrock_response_stream_shape()
        if response_stream_shape is None:
            raise BedrockError(
                status_code=500,
                message=(
                    "Bedrock 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 build_bedrock_stream_error(response_dict, response_stream_shape)
        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")

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Run pip install -U boto3 botocore to get a complete, current Bedrock service model.
  2. Verify the shape loads: python -c "import botocore; from botocore.loaders import Loader; print(Loader().load_service_model('bedrock-runtime', 'service-2'))".
  3. If botocore is intentionally pinned, raise the floor to a version that includes bedrock-runtime event streaming (any recent 1.3x+).
  4. Reinstall in the failing environment (pip install --force-reinstall botocore) to repair a corrupted partial install.
  5. Keep litellm and boto3 upgraded together so the shape-lookup code matches the model file.

Example fix

# before
pip install litellm  # botocore pulled in transitively, possibly stale

# after
pip install -U litellm boto3 botocore
# verify the bedrock-runtime service model is present
python -c "import botocore.session; s=botocore.session.get_session(); m=s.get_service_model('bedrock-runtime'); print(m.shape_for('responseStream'))"
Defensive patterns

Strategy: validation

Validate before calling

from litellm.llms.bedrock.common_utils import get_bedrock_response_stream_shape
if get_bedrock_response_stream_shape() is None:
    raise RuntimeError("botocore bedrock-runtime service model missing - run: pip install -U boto3 botocore")

Type guard

def bedrock_stream_decode_ready() -> bool:
    try:
        from litellm.llms.bedrock.common_utils import get_bedrock_response_stream_shape
    except Exception:
        return False
    return get_bedrock_response_stream_shape() is not None

Try / catch

from litellm.exceptions import BedrockError
try:
    stream = litellm.completion(model="bedrock/<model>", messages=msgs, stream=True)
except BedrockError as e:
    if "event-stream shape could not be loaded" in str(e):
        raise RuntimeError("Fix environment: pip install -U boto3 botocore") from e
    raise

Prevention

When it happens

Trigger: Streaming a bedrock/ completion when botocore is missing, is a stripped/partial install without the bedrock-runtime service model, or the botocore version is so old that the service model JSON lacks the event-stream shape litellm looks up by name.

Common situations: Slim docker images that install botocore-core or vendor only some service models, pinned ancient boto3/botocore versions, CI environments where botocore is downgraded as a transitive dependency, or litellm versions whose shape-lookup key does not match the installed botocore model.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/86b2cf998128641c. Report an issue: GitHub.