Sonnet 4 Converse unexpected "too many images and documents: 19 + 5 > 20" error
Describe the bug
Using us.anthropic.claude-sonnet-4-20250514-v1:0
Error invoking Bedrock us.anthropic.claude-sonnet-4-20250514-v1:0: An error occurred (ValidationException) when calling the Converse operation: The model returned the following errors: too many images and documents: 19 + 5 > 20
Regression Issue
- [ ] Select this option if this issue appears to be a regression.
Expected Behavior
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-runtime/client/converse.html
Per the documentation, up to 20 images & 5 documents should be supported in one message
- You can include up to 20 images. Each image’s size, height, and width must be no more than 3.75 MB, 8000 px, and 8000 px, respectively.
- You can include up to five documents. Each document’s size must be no more than 4.5 MB.
Current Behavior
The model returned the following errors: too many images and documents: 19 + 5 > 20 is being returned
Reproduction Steps
Pass a message containing more than 20 total items (documents + images)
def build_message(role, text):
return {
"role": "user",
"content": [
build_image_content_block_direct_file("../sonnet4_test_files/sample_image1.jpeg"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image2.jpeg"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image3.jpeg"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image4.jpeg"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image5.jpeg"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image6.jpeg"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image7.jpeg"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image8.jpeg"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image9.jpeg"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image10.jpeg"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image11.jpeg"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image12.jpeg"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image13.png"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image14.png"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image15.png"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image16.png"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image17.png"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image18.png"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image19.png"),
build_image_content_block_direct_file("../sonnet4_test_files/sample_image20.png"),
# build_image_content_block_direct_file("../sonnet4_test_files/sample_image21.png"),
build_document_content_block_direct_file("../sonnet4_test_files/sample_doc1.pdf"),
build_document_content_block_direct_file("../sonnet4_test_files/sample_doc2.pdf"),
build_document_content_block_direct_file("../sonnet4_test_files/sample_doc3.pdf"),
build_document_content_block_direct_file("../sonnet4_test_files/sample_doc4.pdf"),
build_document_content_block_direct_file("../sonnet4_test_files/sample_doc5.pdf"),
# build_document_content_block_direct_file("../sonnet4_test_files/sample_doc6.pdf"),
build_text_content_block("Tell me about the files I attached")
]
}
def build_image_content_block_direct_file(input_image):
image_ext = input_image.split(".")[-1]
with open(input_image, 'rb') as image_file:
encoded_image = image_file.read()
return {
"image": {
"format": image_ext,
"source": {
"bytes": encoded_image
}
}
}
def build_document_content_block_direct_file(input_document):
document_ext = input_document.split(".")[-1]
document_name = os.path.basename(input_document).split(".")[0]
with open(input_document, "rb") as f:
document_bytes = f.read()
return {
"document": {
"format": document_ext,
"name": document_name,
"source": {
"bytes": document_bytes
},
"citations": {
"enabled": True
}
}
}
Possible Solution
No response
Additional Information/Context
No response
SDK version used
1.40.22
Environment details (OS name and version, etc.)
Python
Hello @hijaren, thanks for reaching out. I have tried to replicate the above and the closest response I have received is:
The model returned the following errors: messages: too many images: image_count > 20.
Could you please provide a full minimal code of your repro. Also, adding boto3.set_stream_logger('') to show logs would help and please provide the Response body, Response headers and botocore.endpoint [DEBUG] Making request to help us investigate. Please redact any sensitive and security information from your logs if there are.
Hello @hijaren, thanks for reaching out. I have tried to replicate the above and the closest response I have received is:
The model returned the following errors: messages: too many images: image_count > 20.Could you please provide a full minimal code of your repro. Also, adding
boto3.set_stream_logger('')to show logs would help and please provide theResponse body,Response headersandbotocore.endpoint [DEBUG] Making requestto help us investigate. Please redact any sensitive and security information from your logs if there are.
Thanks for looking into this! Please note that I'm sending PDFs with citations on along with the images.
What kind of minimal code are you looking for? It's a big implementation with several system prompts, a tool definition, and s3 downloading logic. Happy to provide whatever you need, asking for clarity.
I tried logging the information but the bytes from the files are drowning the console and I can't catch the details you're looking for. Is there a setting to prevent that?
A minimal code that shows how you call and use the API of the service and sample inputs placeholders that leads to the error. In regards to boto3.set_stream_logger(''), there shouldn't be any blockers that would hinder the logs. It requires boto3 package (import boto3) and the usage of service API. We would like to see the response coming from the service.
Thank you @hijaren! I was able to repro the issue and I can see that the Bedrock Service is giving the error:
2025-10-08 08:47:27,968 urllib3.connectionpool [DEBUG] https://bedrock-runtime.us-east-1.amazonaws.com:443 "POST /model/us.anthropic.claude-3-5-sonnet-20241022-v2%3A0/converse HTTP/1.1" 400 97
2025-10-08 08:47:27,968 botocore.parsers [DEBUG] Response body:
b'{"message":"The model returned the following errors: too many images and documents: 20 + 5 > 20"}'
That being said, I have reached out to the service team about their API and their document and in this regard. I will update as soon as the team has given updates.
Internal Ref: P312896501
Thanks @adev-code, I've deleted my comment containing the gdrive and the log details as a security measure. Let me know if you need anything else!
Hi, meet the same issue. Any update here?