Skip to content

Prefer base64 img/video bytes in Bedrock endpoints#21

Draft
athewsey wants to merge 1 commit intomainfrom
feat/bedrock-vl
Draft

Prefer base64 img/video bytes in Bedrock endpoints#21
athewsey wants to merge 1 commit intomainfrom
feat/bedrock-vl

Conversation

@athewsey
Copy link
Copy Markdown
Collaborator

Issue #, if available: #20

Description of changes:

Align Bedrock input payloads to the Converse API spec (rather than boto3 Python SDK behavior) to un-block saving image understanding use-case load tests to file without changing current serialization setup:

  1. Support base64-pre-encoded image and video bytes in payloads for Bedrock endpoints (by decoding before passing to boto3 which will re-encode again).
  2. Prefer this pre-encoding usage: Issue an informative warning when raw bytes are passed because although this works fine for invocation, it prevents saving request payloads to JSON (and therefore saving Runner results).

Not done yet:

  • Implement unit tests if the general approach is agreed

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Support base64-pre-encoded image and video bytes in payloads for
Bedrock endpoints (by decoding before passing to boto3). Issue a
warning when raw bytes are passed because although this works fine
for invocation, it prevents saving experiment results (per #20)
@acere
Copy link
Copy Markdown
Collaborator

acere commented Feb 23, 2026

Thanks for the PR! i'm reluctant to add this complexity at the connector level, when the issue is really about the json serialization, and considering that most SDK (boto3, OpenAI, Anthropic) seem to prefer handing the serialization of objects themselves.
Did you consider using a custom serializer to handle bytes here?
It would also require a custom deserializer here

This would also address the bytes/string issue for all other file objects: audio, docs, etc.

Here's what I have in mind

class BytesEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, bytes):
            return b64encode(obj).decode("utf-8")
        return super().default(obj)


def bytes_decoder(dct):
    if "bytes" in dct:
        return {"bytes": b64decode(dct["bytes"])}
    return dct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants