← Back to DAGDA | Support | Source: https://github.com/BerriAI/litellm/pull/52547
Skip to content

fix(azure_ai): raise BadRequestError for invalid FLUX 2 image edit input - #52547

Open
shadowmodder wants to merge 2 commits into
BerriAI:mainfrom
shadowmodder:shadowmodder/fix/flux2-image-edit-bad-request
Open

shadowmodder wants to merge 2 commits into
BerriAI:mainfrom
shadowmodder:shadowmodder/fix/flux2-image-edit-bad-request

Conversation

@shadowmodder

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

[insert handwritten description here]

Details

TLDR

Problem this solves:

  • FLUX 2 image edit raised a bare ValueError for bad input
  • The proxy surfaces that as HTTP 500, so clients retry a request that can never succeed

How it solves it:

Intentional product change: invalid FLUX 2 image edit requests now fail with HTTP 400 instead of HTTP 500.

User Flow

Before: a caller sends a FLUX 2 image edit with a missing prompt or image and gets a retryable server error

  1. The caller sends POST http://localhost:4000/v1/images/edits with a FLUX 2 model and no image attached
  2. The proxy answers HTTP 500
  3. Their SDK retries a request that can never succeed

After: the same request fails fast as a client error

  1. The caller sends the same POST http://localhost:4000/v1/images/edits request
  2. The proxy answers HTTP 400 naming the missing prompt or image
  3. Their SDK does not retry it

Relevant issues

Fixes #52533

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Screenshots / Proof of Fix

E2E exception at 8054276f. The full diff is four exception raises in one request transformation plus tests, and the contract is the exception type and status code the transformation raises, which the checks below prove directly. No Azure AI API key is available in my sandbox, so no live provider call was run.

Reproduction script (calls transform_image_edit_request with four invalid inputs: missing prompt, missing image, empty image list, too many reference images):

  • Before, at merge base c030ffb: 4 of 4 cases raised a bare ValueError
  • After: 4 of 4 cases raised litellm.BadRequestError with status_code 400 and the same messages

Tests:

  • pytest tests/unit/llms/azure_ai/image_edit/test_azure_ai_image_edit_transformation.py: 18 passed
  • Mutation check: with only the source file reverted, the 5 affected cases fail (the 2 too-many-references cases and the 3 new missing-input cases). With the fix restored, all 18 pass
  • ruff check and ruff format --check are clean on both changed files

One scope note: _convert_image_to_base64 in the same file also raises ValueError for an unsupported image type. The issue does not name that check, so this PR leaves it unchanged.

Type

Bug Fix

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Signed-off-by: shadowmodder <sudhirvissa@gmail.com>
Signed-off-by: shadowmodder <sudhirvissa@gmail.com>
@veria-ai

veria-ai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

This branch has not been deployed

No deployments
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]: FLUX 2 image edit raises bare ValueErrors instead of 400s for missing/invalid input

1 participant