fix(azure): omit model from deployment image gen and image edit bodies - #27103
Conversation
…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 SummaryThis PR fixes Azure OpenAI deployment-scoped image generation and image edit requests by omitting Confidence Score: 5/5Safe 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: No files require special attention.
|
| 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
…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>
|
@greptile-apps re review |
Align test_azure_image_edit_litellm_sdk with deployment-scoped Azure edits. Co-authored-by: Cursor <cursoragent@cursor.com>
|
bugbot run |
There was a problem hiding this comment.
✅ 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>
|
bugbot run |
|
@greptile-apps re review |
There was a problem hiding this comment.
✅ 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.
…itellm_azure-deployment-image-body
Codecov Report❌ Patch coverage is
📢 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>
|
@greptile-apps re review |
…t-image-body fix(azure): omit model from deployment image gen and image edit bodies
Summary
Azure OpenAI selects the model via
/openai/deployments/{deployment}/...in the URL. Includingmodelin 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
azure.py): POST JSON for deployment-scopedimages/generationsURLs omitsmodel;/providers/...(e.g. FLUX) unchanged.azure/image_edit/transformation.py): multipartdataomitsmodelwhen the resolved URL is deployment-scopedimages/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
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
modelfrom the outbound payload: JSON bodies for.../openai/deployments/.../images/generationsand multipart form fields for.../openai/deployments/.../images/editsno longer includemodel, 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.