BerriAI/litellm · error · ImportError

Missing boto3 to call bedrock. Run 'pip install boto3'.

Error message

Missing boto3 to call bedrock. Run 'pip install boto3'.

What it means

The Bedrock rerank request preparer needs botocore's SigV4Auth/AWSRequest to sign the request. If botocore (installed with boto3) is not importable, an ImportError is raised: 'Missing boto3 to call bedrock. Run pip install boto3.' Boto3 is an optional dependency for litellm's Bedrock support.

Source

Thrown at litellm/llms/bedrock/rerank/handler.py:142

        )

        response_json: Final = response.json()

        return BedrockRerankConfig()._transform_response(response_json)

    def _prepare_request(
        self,
        model: str,
        api_base: str | None,
        extra_headers: dict | None,
        data: dict,
        optional_params: dict,
    ) -> BedrockPreparedRequest:
        try:
            from botocore.auth import SigV4Auth
            from botocore.awsrequest import AWSRequest
        except ImportError:
            raise ImportError("Missing boto3 to call bedrock. Run 'pip install boto3'.")
        boto3_credentials_info: Final = self._get_boto_credentials_from_optional_params(optional_params, model)

        ### SET RUNTIME ENDPOINT ###
        _, proxy_endpoint_url = self.get_runtime_endpoint(
            api_base=api_base,
            aws_bedrock_runtime_endpoint=boto3_credentials_info.aws_bedrock_runtime_endpoint,
            aws_region_name=boto3_credentials_info.aws_region_name,
        )
        proxy_endpoint_url = proxy_endpoint_url.replace("bedrock-runtime", "bedrock-agent-runtime")
        proxy_endpoint_url = f"{proxy_endpoint_url}/rerank"
        sigv4: Final = SigV4Auth(
            boto3_credentials_info.credentials,
            "bedrock",
            boto3_credentials_info.aws_region_name,
        )
        # Make POST Request
        body: Final = json.dumps(data).encode("utf-8")

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. pip install boto3
  2. Add boto3 to the project's dependency manifest if any Bedrock route is used.
  3. Verify import: python -c "from botocore.auth import SigV4Auth".
  4. Check pip check for broken dependency resolution that dropped botocore.

Example fix

# before: ImportError on litellm.rerank(model='bedrock/...')
pip install litellm

# after
pip install litellm boto3
Defensive patterns

Strategy: try-catch

Validate before calling

def boto3_available() -> bool:
    try:
        from botocore.auth import SigV4Auth  # noqa: F401
        return True
    except ImportError:
        return False

Type guard

def can_prepare_bedrock_request() -> bool:
    return boto3_available()

Try / catch

try:
    litellm.rerank(model="bedrock/...", query=q, documents=docs)
except ImportError as e:
    if "boto3" in str(e):
        raise SetupError("pip install boto3") from e
    raise

Prevention

When it happens

Trigger: litellm.rerank(model='bedrock/...') (or any path going through _prepare_request) in an environment where boto3/botocore was never installed or was uninstalled by a dependency resolver.

Common situations: Slim Docker images that strip boto3; pip dependency conflicts removing botocore; using litellm only for OpenAI previously and adding Bedrock later without installing boto3.

Related errors


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