Skip to content

fix(azure): omit model from deployment image gen and image edit bodies - #27103

Merged
Sameerlite merged 6 commits into
litellm_internal_stagingfrom
litellm_azure-deployment-image-body
May 5, 2026
Merged

fix(azure): omit model from deployment image gen and image edit bodies#27103
Sameerlite merged 6 commits into
litellm_internal_stagingfrom
litellm_azure-deployment-image-body

Conversation

@Sameerlite

@Sameerlite Sameerlite commented May 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Azure OpenAI selects the model via /openai/deployments/{deployment}/... in the URL. Including model in the JSON body (image generation) or multipart form fields (image edits) sends the deployment resource name, which Azure rejects for gpt-image-2 (invalid_value / model does not exist). This aligns LiteLLM with direct Azure REST calls.

Changes

  • Image generation (azure.py): POST JSON for deployment-scoped images/generations URLs omits model; /providers/... (e.g. FLUX) unchanged.
  • Image edit (azure/image_edit/transformation.py): multipart data omits model when the resolved URL is deployment-scoped images/edits.

Tests

  • tests/test_litellm/llms/azure/image_generation/test_azure_image_generation_init.py — wire payload assertions + helper coverage.
  • tests/test_litellm/llms/azure/image_edit/test_azure_image_edit_transformation.py — new tests for form-data stripping and transform.

Fixes #26539
Fixes LIT-2757

image

Note

Low Risk
Low risk: change is narrowly scoped to Azure deployment-style image endpoints and is covered by new/updated tests, but it slightly alters wire payloads for those routes.

Overview
Azure deployment-scoped image calls now strip model from the outbound payload: JSON bodies for .../openai/deployments/.../images/generations and multipart form fields for .../openai/deployments/.../images/edits no longer include model, relying on the deployment in the URL instead.

This adds a provider hook (finalize_image_edit_multipart_data) so image-edit providers can adjust form fields after URL resolution, updates request/fixture expectations, and adds targeted tests to assert the on-the-wire payload for both deployment and non-deployment (/providers/...) routes.

Reviewed by Cursor Bugbot for commit c53c71a. Bugbot is set up for automated code reviews on this repo. Configure here.

…t requests

Azure OpenAI routes image gen/edit by deployment in the URL; sending the
deployment id in model breaks gpt-image-2 (invalid_value). Strip model from
JSON for deployments/.../images/generations and from multipart data for
.../images/edits. Non-deployment URLs (e.g. Azure AI FLUX) unchanged.

Fixes #26316.

Co-authored-by: Cursor <cursoragent@cursor.com>
@greptile-apps

greptile-apps Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes Azure OpenAI deployment-scoped image generation and image edit requests by omitting model from the JSON body and multipart form fields respectively, since Azure routes by deployment name in the URL and rejects model in the payload (notably for gpt-image-2). The implementation adds a finalize_image_edit_request_data hook to the base image-edit config (no-op by default), overridden in AzureImageEditConfig to strip model when the resolved URL matches the deployment pattern, and applies a parallel helper for image generation in azure.py. Tests are updated to assert the corrected wire payload and now mock at the HTTPHandler.post level for stronger integration coverage.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to Azure deployment-style image endpoints, aligns with Azure's documented API contract, and is covered by updated tests that assert the wire payload directly.

No P0 or P1 issues found. The fix is correct: azure_deployment_image_generation_json_body and azure_deployment_image_edit_form_data both create new dicts (no mutation of the original), the URL detection strings are specific enough to avoid false positives on non-deployment URLs, and finalize_image_edit_request_data is called after get_complete_url so it always receives the fully-resolved URL. Test updates correctly replace the old high-level mock with lower-level HTTPHandler.post mocking to actually exercise the filter in the integration path.

No files require special attention.

Important Files Changed

Filename Overview
litellm/llms/azure/image_generation/http_utils.py New helper that strips model from the JSON body for deployment-scoped Azure image generation URLs; clean, no logic issues.
litellm/llms/azure/image_edit/transformation.py Adds azure_deployment_image_edit_form_data static method and finalize_image_edit_request_data override to strip model from multipart fields for deployment-scoped edit URLs.
litellm/llms/base_llm/image_edit/transformation.py Adds no-op finalize_image_edit_request_data hook to the base class, allowing provider subclasses to post-process form data after URL resolution.
litellm/llms/custom_httpx/llm_http_handler.py Calls finalize_image_edit_request_data(data, api_base) in both sync and async image-edit handlers after URL resolution and before logging/sending; correctly placed.
litellm/llms/azure/azure.py Applies azure_deployment_image_generation_json_body to filter the JSON body before both sync and async image generation POSTs.
tests/test_litellm/llms/azure/image_generation/test_azure_image_generation_init.py Updates integration tests to mock at HTTPHandler.post level and assert model is absent from the wire JSON; adds two unit tests for the new helper.
tests/test_litellm/llms/azure/image_edit/test_azure_image_edit_transformation.py New unit tests for azure_deployment_image_edit_form_data and finalize_image_edit_request_data; pure mock, no network calls.
tests/image_gen_tests/test_image_edits.py Updates test_azure_image_edit_litellm_sdk assertion to expect model absent from multipart form-data, aligning with the new wire behavior.
tests/image_gen_tests/request_payloads/azure_gpt_image_1.json Removes model from the fixture file to match the updated expected wire payload.

Reviews (4): Last reviewed commit: "refactor(azure): move image gen JSON hel..." | Re-trigger Greptile

Comment thread litellm/llms/azure/image_edit/transformation.py Outdated
…mage edit URL

- Image generation tests patch HTTPHandler.post / get_async_httpx_client so
  make_*_azure_httpx_request runs and wire json is asserted on call kwargs.
- Azure image edit: strip model in finalize_image_edit_multipart_data using the
  same URL string the handler passes to POST (no second get_complete_url in
  transform). BaseImageEditConfig default finalize is a no-op.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Sameerlite

Copy link
Copy Markdown
Contributor Author

@greptile-apps re review

Align test_azure_image_edit_litellm_sdk with deployment-scoped Azure edits.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Sameerlite

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 41ac026. Configure here.

Expected JSON matches deployment-scoped Azure POST (#26316).

Co-authored-by: Cursor <cursoragent@cursor.com>
@Sameerlite

Copy link
Copy Markdown
Contributor Author

bugbot run

@Sameerlite

Copy link
Copy Markdown
Contributor Author

@greptile-apps re review

@cursor cursor Bot left a comment

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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c53c71a. Configure here.

@mateo-berri mateo-berri left a comment

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.

Some non-blocking feedback but otherwise LGTM! Thanks

Also, fix the CI tests

Comment thread litellm/llms/azure/azure.py Outdated
Comment thread litellm/llms/base_llm/image_edit/transformation.py Outdated
@codecov

codecov Bot commented May 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.21053% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/llms/custom_httpx/llm_http_handler.py 0.00% 2 Missing ⚠️
litellm/llms/base_llm/image_edit/transformation.py 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

…ze hook

- Add image_generation/http_utils.azure_deployment_image_generation_json_body; call
  from azure.py (keeps AzureChatCompletion focused on chat).
- Rename finalize_image_edit_multipart_data to finalize_image_edit_request_data with
  docstring covering multipart and JSON POST payloads (review feedback).

Co-authored-by: Cursor <cursoragent@cursor.com>
@Sameerlite

Copy link
Copy Markdown
Contributor Author

@greptile-apps re review

@Sameerlite
Sameerlite merged commit b0edffb into litellm_internal_staging May 5, 2026
116 checks passed
@Sameerlite
Sameerlite deleted the litellm_azure-deployment-image-body branch May 5, 2026 03:39
@cdvankammen cdvankammen mentioned this pull request Jun 2, 2026
1 task
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…t-image-body

fix(azure): omit model from deployment image gen and image edit bodies
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