Repository navigation
fix(images): forward gpt-image supported params like background to OpenAI and Azure - #39525
Conversation
…enAI and Azure Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
Greptile SummaryThis PR forwards the full parameter set supported by GPT image-generation adapters and preserves image metadata echoed by OpenAI and Azure.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/utils.py | Extends image-generation parameter normalization so adapter-supported parameters survive filtering and are forwarded through the existing provider mapping path. |
| litellm/llms/openai/image_generation/gpt_transformation.py | Preserves provider-echoed image metadata and falls back to requested or default values when metadata is absent. |
| litellm/types/utils.py | Retains the provider-returned background field when constructing and serializing an ImageResponse. |
| tests/test_litellm/test_utils.py | Covers forwarding GPT image parameters for both OpenAI and Azure while retaining unknown parameters in extra_body. |
| tests/test_litellm/llms/openai/image_generation/test_gpt_transformation.py | Covers preservation of metadata echoed by OpenAI and Azure image-generation responses. |
| tests/test_litellm/types/test_types_utils.py | Verifies that ImageResponse retains and serializes the background field. |
Reviews (3): Last reviewed commit: "fix(image_gen): keep the provider's echo..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…format on gpt-image responses
|
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 ec2e35b. Configure here.
4b1e24e
into
litellm_internal_staging
TLDR
Problem this solves:
background,output_format,moderation,output_compressionsilently dropped for gpt-image models, on bothopenai/gpt-image-*andazure/gpt-image-*"background": nulleven when the provider echoed itoutput_formatandqualityfrom request defaults, so a jpeg request came back labelledpngand the quality tier Azure actually used was overwritten withhighHow it solves it:
ImageResponsenow keeps thebackgroundfield the provider returnedsize,quality, andoutput_formatand falls back to the request values (folds in the response-side fix from fix(image-generation): preserve requested output format #34262)User Flow
Before: a developer asking gpt-image-2 for a transparent PNG gets an opaque image back
{"model": "gpt-image-2", "prompt": "a red apple", "background": "transparent", "output_format": "png"}"background": nulland the PNG has a solid background"model": "azure-gpt-image-2": the request that reaches Azure has nobackgroundoroutput_formatkey"output_format": "jpeg"returns PNG bytes labelled"output_format": "png"After: the same request produces a transparent PNG
"background": "transparent"and"output_format": "png"backgroundandoutput_format, and the image comes back with an alpha channel"background": "transparent""output_format": "jpeg"returns JPEG bytes labelled"output_format": "jpeg", andqualityis the tier the provider reportsRelevant issues
Fixes #38649
Linear ticket
Resolves LIT-6836
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<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@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Real OpenAI and real Azure OpenAI (a Sweden Central gpt-image-2 deployment), real cost. Two worktrees with their own venvs, each proxy booted from its own tree with
PYTHONPATHpointed at it (litellm.__file__checked inside that tree),--num_workers 2, noDATABASE_URLso both run DB-less. Before is the merge base 658f506 on port 53213, after is the tip ec2e35b on port 42828, same config, same script, same order89504e47is the PNG magic,ffd8ffe0is JPEG, andhasAlphacomes fromsipsBefore (658f506, port 53213)
After (ec2e35b, port 42828)
The same azure jpeg request sent straight to Azure with no
qualityechoes"quality":"low", which is what the before leg overwrote withhighObservations from the run:
qualityecho becamehigh; this PR fixes itresponse_formatrejection for gpt-image-2 identical on both legsType
🐛 Bug Fix
Caveats (if any)
Low
qualitynow uses the echoed tierFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/e2daaef76ead48c687fd33ad2c258672
Open in Devin Desktop: https://app.devin.ai/desktop/session/e2daaef76ead48c687fd33ad2c258672?variant=devin