- Newest
- Most votes
- Most comments
Hello,
I understand you're getting the error "Can't invoke 'us.meta.llama4-scout-17b-instruct-v1:0’. Reason: Expecting ',' delimiter: line 279 column 22 (char 7332)” when trying to process a PDF file in AWS Bedrock.
The error basically occurs because raw PDF data can't be directly embedded in JSON requests. This breaks the JSON formatting, leading to the error you're seeing.
-
Use Base64 Encoding (For smaller files): Only encode the file content - don't include PDF headers or metadata.
-
Additionally, you can use S3 as Reference Method (Recommended for larger files):
If the model you’re invoking supports it, you can just pass an S3 URI in the request. This avoids hitting JSON size or encoding issues:
======= { "inputDocuments": [ { "s3Uri": "s3://your-bucket-name/path/to/file.pdf" } ] } =======
If you have any further questions, please reach out to AWS Support [1] and we would be happy to assist you further.
References—
answered a year ago
When working with binary files like PDFs in Amazon Bedrock, you need to handle the raw bytes correctly to avoid breaking the JSON format of your request. Here's how to address your issue:
For binary data like PDFs, you should use the "bytes" field in the DocumentSource object, which expects Base64-encoded binary data. When using an AWS SDK, you don't need to manually encode the bytes in base64 - the SDK handles this for you.
The error you're seeing ("Expecting ',' delimiter") suggests that raw binary data is being inserted directly into your JSON request, corrupting the JSON structure.
If you're using an AWS SDK:
- Read the PDF file as binary data
- Pass the raw binary data directly to the "bytes" field in your DocumentSource
- Let the SDK handle the Base64 encoding
If you're making direct API calls without an SDK:
- Read the PDF file as binary data
- Base64 encode the binary data
- Include the encoded string in your request
Don't try to modify the PDF header or structure - the entire file should be treated as binary data. The model will recognize it as a PDF based on the content, not based on how you label it.
Note that Bedrock Agents currently cannot process images through the files parameter, but they can process document files like PDFs for text extraction.
Sources
DocumentSource - Amazon Bedrock
Send images as Base64 files to AWS BedRock Agent | AWS re:Post
Community | How to embed model-specific request payloads when using Amazon Bedrock's InvokeModel API
answered a year ago
The error usually means your request payload is no longer valid JSON after you inject the PDF bytes. Two key tips:
When including binary data in a JSON request, Base64-encode only the file contents, not the PDF header or metadata.
Double-check you’re escaping quotes properly — many JSON libraries will choke if the byte data contains unescaped characters.
If you’re using Python or Node, construct the request like:
import base64, json
with open("file.pdf", "rb") as f: encoded = base64.b64encode(f.read()).decode("utf-8")
payload = { "input": { "document": { "name": "file.pdf", "data": encoded, "mimeType": "application/pdf" } } }
print(json.dumps(payload)) # Should serialize cleanly
This ensures the payload is valid JSON and recognized as a PDF.
answered a year ago

Hi, when I try to encode the file in base64, it is no longer detected as a PDF file. However, I cannot add the %PDF-x.x header back in because it is no longer in Base64 format. If possible, could you please provide an example of how you were able to implement a PDF file in Base64 encoding? Thank you! Also the model I am using does not support S3 as a reference method unfortunately.