BerriAI/litellm · error · ImportError

boto3/botocore is required for AWS event stream parsing

Error message

boto3/botocore is required for AWS event stream parsing

What it means

Parsing the AWS event-stream for Bedrock InvokeAgent relies on botocore's EventStreamBuffer and EventStreamJSONParser. If neither boto3 nor botocore is importable, this ImportError is raised at response-parse time — the HTTP request may already have been sent and paid for before the failure.

Solutions

  1. Install the SDK: pip install boto3 (botocore ships with it)
  2. Or install LiteLLM with the extra: pip install 'litellm[bedrock]'
  3. Add boto3 explicitly to your deployment image/requirements so it is never pruned
  4. Add a startup health check importing botocore.eventstream to fail fast before traffic

Example fix

// before
# only litellm installed → ImportError at stream-parse time

// after
pip install 'litellm[bedrock]'   # or: pip install boto3
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util

if importlib.util.find_spec("botocore") is None:
    raise RuntimeError("boto3/botocore is required for invoke-agent streaming — pip install 'litellm[bedrock]'")

resp = litellm.completion(model="agent/ID/ALIAS", messages=msgs, stream=True)

Type guard

def invoke_agent_dependencies_available() -> bool:
    """True when botocore's event-stream parser is importable."""
    return importlib.util.find_spec("botocore") is not None

Try / catch

try:
    resp = litellm.completion(model="agent/ID/ALIAS", messages=msgs, stream=True)
except ImportError as e:
    raise RuntimeError("Install AWS SDK: pip install boto3") from e

Prevention

When it happens

Trigger: Any streaming invoke-agent call on an environment where boto3/botocore was never installed: slim Docker images, Lambda layers without the AWS SDK, CI images that prune 'unused' deps, or litellm installed without the bedrock extra.

Common situations: Teams that previously used only OpenAI-style providers adopting the agent/agentcore paths; minimized containers; dependency resolvers that drop optional boto3 when nothing else pins it.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

Thrown at litellm/llms/bedrock/chat/invoke_agent/transformation.py:172

    ) -> dict:
        # use the last message content as the query
        query: Final[str] = convert_content_list_to_str(messages[-1])
        return {
            "inputText": query,
            "enableTrace": True,
            **optional_params,
        }

    def _parse_aws_event_stream(self, raw_content: bytes) -> InvokeAgentEventList:
        """
        Parse AWS event stream format using boto3/botocore's built-in parser.
        This is the same approach used in the existing AWSEventStreamDecoder.
        """
        try:
            from botocore.eventstream import EventStreamBuffer
            from botocore.parsers import EventStreamJSONParser
        except ImportError:
            raise ImportError("boto3/botocore is required for AWS event stream parsing")

        events: Final[InvokeAgentEventList] = []
        parser: Final = EventStreamJSONParser()
        event_stream_buffer: Final = EventStreamBuffer()

        # Add the entire response to the buffer
        event_stream_buffer.add_data(raw_content)

        # Process all events in the buffer
        for event in event_stream_buffer:
            try:
                headers = self._extract_headers_from_event(event)

                event_type = headers.get("event_type", "")

                if event_type == "chunk":
                    # Handle chunk events specially - they contain decoded content, not JSON
                    message = self._parse_message_from_event(event, parser)

View on GitHub (pinned to 77b7c6c40c)