Skip to content

Conversation

@dor-tzur-lmnd
Copy link

@dor-tzur-lmnd dor-tzur-lmnd commented Dec 22, 2025

Relevant issues

Fixes binary file upload to Vertex AI (UnicodeDecodeError when uploading PDFs/images)

Pre-Submission checklist

  • I have Added testing in the tests/litellm/ directory
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix

Changes

Fixed UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff when uploading binary files (PDFs, images) to Vertex AI via the /files endpoint.

Root cause: The file upload handler was calling .decode("utf-8") on binary file content before sending to httpx, which fails for non-UTF-8 binary data.

Fix:

  1. Removed the unnecessary .decode("utf-8") call - httpx accepts bytes directly
  2. Changed data= to content= - the correct httpx parameter for raw body content
  3. Applied fix to both sync (create_file) and async (async_create_file) code paths

…ontent' instead of 'data' for httpx compatibility

[agent]
…seLLMHTTPHandler

- Implemented tests to ensure that the async_create_file and create_file methods correctly handle binary data without raising UnicodeDecodeError.
- Verified that the original binary content is passed directly to the httpx client without modification.
- Added regression tests for issues related to uploading binary files to Vertex AI.
[agent]
- Eliminated the synchronous test for create_file that handled binary data, as it was redundant with the existing async test.
- Cleaned up the test file by removing unnecessary imports and comments.f
[agent]
@vercel
Copy link

vercel bot commented Dec 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
litellm Ready Ready Preview, Comment Dec 22, 2025 4:41pm

@CLAassistant
Copy link

CLAassistant commented Dec 22, 2025

CLA assistant check
All committers have signed the CLA.

@dor-tzur-lmnd dor-tzur-lmnd changed the title Fix vertex binary issue fix: vertex binary issue Dec 22, 2025
- Removed redundant comments regarding HTTPX data handling in the file upload methods.
- Streamlined the code for better readability while maintaining functionality.
[agent]
- Added detailed comments to clarify the mocking of binary content, provider configuration, logging, and HTTP response in the async_create_file test.
- Verified that binary content is passed directly to the HTTP client without modification, ensuring robust handling of invalid UTF-8 bytes.
[agent]
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