Skip to content

fix: encode interaction media bytes#2458

Open
pragnyanramtha wants to merge 2 commits into
googleapis:mainfrom
pragnyanramtha:codex/interactions-bytes-base64
Open

fix: encode interaction media bytes#2458
pragnyanramtha wants to merge 2 commits into
googleapis:mainfrom
pragnyanramtha:codex/interactions-bytes-base64

Conversation

@pragnyanramtha
Copy link
Copy Markdown

Fixes #2427.

Summary

  • treat raw bytes as valid Interactions base64 media input
  • base64-encode raw bytes in both sync and async request transforms
  • add regression coverage for image, audio, video, and document content blocks so transformed requests remain JSON-serializable

Tests

  • .venv/bin/pytest google/genai/tests/interactions/test_base64_inputs.py google/genai/tests/interactions/test_auth.py google/genai/tests/interactions/test_integration.py -q
  • .venv/bin/python -m compileall -q google/genai/_interactions/_files.py google/genai/_interactions/_types.py google/genai/_interactions/_utils/_transform.py google/genai/tests/interactions/test_base64_inputs.py
  • git diff --check

Note: I also ran pytest google/genai/tests/interactions -q; the non-credential tests passed, but test_paths.py requires local API key/ADC credentials and failed during fixture setup before exercising this patch.

@pragnyanramtha pragnyanramtha marked this pull request as ready for review May 16, 2026 18:55
@pragnyanramtha
Copy link
Copy Markdown
Author

Refreshed this branch with current main and re-ran the focused validation.

Validation:

  • .venv/bin/pytest google/genai/tests/interactions/test_base64_inputs.py google/genai/tests/interactions/test_auth.py google/genai/tests/interactions/test_integration.py -q -> 29 passed
  • .venv/bin/python -m compileall -q google/genai/_interactions/_files.py google/genai/_interactions/_types.py google/genai/_interactions/_utils/_transform.py google/genai/tests/interactions/test_base64_inputs.py -> passed
  • git diff --check origin/main...HEAD -> passed

@pragnyanramtha
Copy link
Copy Markdown
Author

Refreshed this branch with current main in 8241320.

Validation rerun after the base update:

  • .venv/bin/python -m pytest google/genai/tests/interactions/test_base64_inputs.py google/genai/tests/interactions/test_auth.py google/genai/tests/interactions/test_integration.py -q -> 29 passed, 1 experimental warning
  • .venv/bin/python -m compileall -q google/genai/_interactions/_files.py google/genai/_interactions/_types.py google/genai/_interactions/_utils/_transform.py google/genai/tests/interactions/test_base64_inputs.py -> passed
  • git diff --check origin/main...HEAD -> passed

@pragnyanramtha pragnyanramtha force-pushed the codex/interactions-bytes-base64 branch from 8241320 to 6c1800d Compare May 21, 2026 06:22
@Venkaiahbabuneelam Venkaiahbabuneelam self-assigned this May 22, 2026
@Venkaiahbabuneelam Venkaiahbabuneelam added the size:L Code changes between 40-100 lines label May 22, 2026
@Venkaiahbabuneelam
Copy link
Copy Markdown

Hi @pragnyanramtha, Thanks for reaching out us!

Some checks have failed, please resolve the conflicts.
Thanks



def is_base64_file_input(obj: object) -> TypeGuard[Base64FileInput]:
return isinstance(obj, io.IOBase) or isinstance(obj, os.PathLike)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return
isinstance(obj , io.IOBase)
or isinstance or Isinstance
(obj , os.PathLike))
import io
import os

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

Labels

size:L Code changes between 40-100 lines status:awaiting user response

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cannot send the image as bytes in the input, found "TypeError: Object of type bytes is not JSON serializable"

3 participants