Skip to content

fix(proxy): keep image-edit uploads as files instead of strings (#41421) - #41428

Closed
nikolas-sapa wants to merge 5 commits into
BerriAI:mainfrom
nikolas-sapa:fix/proxy-image-edit-bytes-41421
Closed

nikolas-sapa wants to merge 5 commits into
BerriAI:mainfrom
nikolas-sapa:fix/proxy-image-edit-bytes-41421

Conversation

@nikolas-sapa

@nikolas-sapa nikolas-sapa commented Sep 16, 2026 •

Copy link
Copy Markdown

Fixes #41421.

Sending an image[] file to the proxy /v1/images/edits endpoint failed with "Invalid type for 'image[0]': expected a file, but got a string instead."

Cause: _read_request_body left the collapsed image[] entry in the parsed body, while the real uploads were converted separately to BytesIO lists. Downstream flattening then str()-ed the leftover into a form field.

Changes (isolated scope):

  • litellm/proxy/image_endpoints/endpoints.py: drop raw image/image[]/mask/mask[] keys from the parsed body (the File() params are the source of truth), and 422 when those fields arrive as plain strings.
  • litellm/llms/openai/image_edit/transformation.py: keep the BytesIO .name set by the proxy instead of hardcoding image.png/mask.png.

Regression coverage lives in tests/test_litellm/proxy/image_endpoints/test_endpoints.py and tests/test_litellm/llms/openai/test_openai_image_edit_transformation.py. The earlier standalone test_image_edit_upload.py was removed when the tests moved into these mapped files. This description update does not represent a new local test run.

@nikolas-sapa
nikolas-sapa requested a review from a team September 16, 2026 15:27
@CLAassistant

CLAassistant commented Sep 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codspeed

codspeed Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing nikolas-sapa:fix/proxy-image-edit-bytes-41421 (25cf74d) with main (8fc9c46)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with the previously reported placement, typing, and redundant source-comment concerns addressed

Findings

  1. P2 Regression Tests Misplaced ▶
  2. P2 Redundant Source Comment ▶

Summary

The PR keeps image-edit uploads as file objects, removes duplicate parsed form entries, preserves uploaded filenames, and adds regression coverage in the mapped test files

  • Rejects string values supplied for image and mask file fields
  • Preserves all repeated bracket-style uploads
  • Uses safe default filenames when file objects have no usable name
  • Moves regression coverage into the existing endpoint and transformation test modules

Reviews (2) · Last reviewed commit: "test: cover BytesIO mask filename preser..."

@@ -0,0 +1,151 @@
"""Regression test for BerriAI/litellm#41421.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Regression Tests Misplaced

This bug fix creates a separate test file, violating the requirement to extend the existing mapped endpoint and transformation tests before merging

Context Used: CLAUDE.md (source)

Comment thread tests/test_litellm/proxy/image_endpoints/test_image_edit_upload.py Outdated
Comment on lines +309 to +313
# Drop raw file keys parsed from the multipart body. The File() params
# above are the source of truth (they capture every repeat of `image[]`);
# leaving the collapsed UploadFile/str behind would let downstream
# flattening `str()` it into a form field OpenAI rejects as
# "expected a file, but got a string instead" (#41421).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Redundant Source Comment

This comment restates straightforward filtering, violating the requirement to reserve source comments for genuinely complex business logic before merging

Suggested change
# Drop raw file keys parsed from the multipart body. The File() params
# above are the source of truth (they capture every repeat of `image[]`);
# leaving the collapsed UploadFile/str behind would let downstream
# flattening `str()` it into a form field OpenAI rejects as
# "expected a file, but got a string instead" (#41421).

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@nikolas-sapa
nikolas-sapa force-pushed the fix/proxy-image-edit-bytes-41421 branch from 8703dd5 to 6f438da Compare September 16, 2026 16:26
@nikolas-sapa

Copy link
Copy Markdown
Author

@greptile-apps re-review please — the three P2 findings (misplaced test file, Any types, redundant comment) were addressed in 6f438da: tests moved into the mapped endpoint/transformation test files, the new file deleted, and the source comment removed.

@nikolas-sapa
nikolas-sapa force-pushed the fix/proxy-image-edit-bytes-41421 branch from 3774b84 to 5720a49 Compare September 17, 2026 11:54
@nikolas-sapa
nikolas-sapa force-pushed the fix/proxy-image-edit-bytes-41421 branch from cd43a3d to 25cf74d Compare September 18, 2026 15:10

Copy link
Copy Markdown
Contributor

Thanks for the fix and for the quick turnaround on review feedback, @nikolas-sapa — much appreciated.

Heads up so you do not spend more time on it: the underlying bug (#41421) was fixed and shipped in #39512, which landed on main yesterday, so this PR is now superseded. Closing it out — sorry for the duplicated effort, and thanks again for the report and the patch.

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.

[Bug]: LiteLLM Proxy 1.100.0 serializes image-edit uploads as strings for OpenAI GPT Image models

3 participants