BerriAI/litellm · error · ValueError

Bedrock Converse only supports base64-encoded document…

Error message

Bedrock Converse only supports base64-encoded document sources, got '{source_type}'. Please convert the document to base64 before sending to Bedrock.

What it means

Bedrock document handling guard: _process_document_message received a document source that is not base64-encoded (e.g. a URL or file_id); Bedrock Converse only accepts base64 document bytes, so the caller must convert first.

Solutions

  1. Convert the document to a base64-encoded source before sending to Bedrock Converse.
  2. Fetch URL/bytes documents and re-encode them as base64.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/litellm_core_utils/prompt_templates/factory.py:4645 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/4066cf0b4dd653f8. Report an issue: GitHub.

Appendix: source

Thrown at litellm/litellm_core_utils/prompt_templates/factory.py:4645

        if file_data is None and file_id is None:
            raise litellm.BadRequestError(
                message=f"file_data and file_id cannot both be None. Got={message}",
                model="",
                llm_provider="bedrock",
            )
        return await BedrockImageProcessor.process_image_async(image_url=cast(str, file_id or file_data), format=format)

    @staticmethod
    def _process_document_message(element: dict) -> BedrockContentBlock:
        """Convert a document content block to a Bedrock DocumentBlock.

        Handles the Anthropic-style document format:
        {"type": "document", "source": {"type": "base64", "media_type": "application/pdf", "data": "..."}}
        """
        source: Final = element["source"]
        source_type: Final = source.get("type")
        if source_type != "base64":
            raise ValueError(
                f"Bedrock Converse only supports base64-encoded document sources, got '{source_type}'. "
                "Please convert the document to base64 before sending to Bedrock."
            )
        media_type: Final[str] = source["media_type"]
        data: Final[str] = source["data"]
        doc_format = BedrockImageProcessor._validate_format(mime_type=media_type, image_format=media_type.split("/")[1])

        # Deterministic name using the same hashing pattern as _create_bedrock_block
        HASH_SAMPLE_BYTES: Final = 64 * 1024
        normalized: Final = "".join(data.split()).encode("utf-8")
        sample: Final = normalized[:HASH_SAMPLE_BYTES]
        hasher: Final = hashlib.sha256()
        hasher.update(sample)
        hasher.update(str(len(normalized)).encode("utf-8"))
        content_hash: Final = hasher.hexdigest()[:16]
        document_name: Final = f"Document_{content_hash}_{doc_format}"

        return BedrockContentBlock(

View on GitHub (pinned to 77b7c6c40c)