Repository navigation
fix(azure_ai): bill FLUX.2 by the megapixels Azure reports in request_meta - #43094
devin-ai-integration[bot] wants to merge 5 commits into
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…_input_image_billing
…oxy edits bill the deployment rate
|
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 3608ba3. Configure here.
what to review
FLUX.2 edits on Azure logged about half of what Azure bills. LiteLLM now bills the megapixels Azure itself reports on every response
summary
request_metakeeps the old output-only costinput_cost_per_pixeldecisions
input_mp + output_mpis the billed quantity, so no image parsing and no per-image countinput_cost_per_pixelrate for input and output megapixels, since Azure prices both at $0.05/MPTLDR
Problem this solves:
How it solves it:
request_meta.input_mpandoutput_mpfrom the responseinput_cost_per_pixel * 2^20 * (input_mp + output_mp)User Flow
Before: a team editing images through Azure FLUX.2-flex sees LiteLLM spend well below their Azure invoice
size=1024x1024x-litellm-response-cost: 0.0524288whatever they uploaded, even a 12 MP photoAfter: the same edit is priced from Azure's own measurement of the call
0.1for one 1024x1024 reference and0.6315for one 4032x3024 photo, which Azure measured at 11.63 MPRelevant issues
Affected release
Linear ticket
Resolves LIT-8140
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
Both proxies run the same config against a real Azure AI Foundry FLUX.2-flex deployment:
azure_ai/FLUX.2-flexat the catalog rate,flux-flex-overridewithinput_cost_per_pixel: 1.5e-07, andflux-flex-zerorefwithinput_cost_per_pixel: 0.0. Base runs on port 4100, tip on 4200. The reference images are PNGs of the size in each case nameEdits are sent as
curl -s -D - -o /dev/null localhost:$PORT/v1/images/edits -H "Authorization: Bearer $KEY" -F model=$MODEL -F prompt="make it a watercolor" -F size=1024x1024 -F "image[]=@ref.png"(one-F "image[]=..."per reference). Generations arecurl -s -D - -o /dev/null localhost:$PORT/v1/images/generations -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"model":"azure_ai/FLUX.2-flex","prompt":"a watercolor fox","size":"<size>"}'Azure's own
request_metafor these calls, from direct calls to the deployment: 640x640 generation 0 in / 0.39 out, one 640x640 ref 0.39 / 1.0, one 1024x1024 ref 1.0 / 1.0, one 1280x720 ref 0.88 / 1.0, three 1024x1024 refs 3.0 / 1.0, one 4032x3024 ref 11.63 / 1.0, one 8000x6000 ref 45.78 / 1.0, 4032x3024 plus 640x640 refs 2.0 / 1.0Before (37f5267)
x-litellm-response-cost per call
gen 640x640returnsHTTP 200,0.02048gen 1024x1024returnsHTTP 200,0.0524288edit 1 ref 640x640returnsHTTP 200,0.0524288edit 1 ref 1024x1024returnsHTTP 200,0.0524288edit 1 ref 1280x720returnsHTTP 200,0.0524288edit 3 refs 1024x1024returnsHTTP 200,0.0524288edit 1 ref 4032x3024returnsHTTP 200,0.0524288edit 1 ref 8000x6000returnsHTTP 200,0.0524288edit 2 refs 4032x3024 + 640x640returnsHTTP 200,0.0524288flux-flex-override, 1 ref 4032x3024returnsHTTP 200,0.0524288flux-flex-zeroref, 1 ref 4032x3024returnsHTTP 200,0.0524288After (61a361a)
x-litellm-response-cost per call
gen 640x640returnsHTTP 200,0.0195gen 1024x1024returnsHTTP 200,0.05edit 1 ref 640x640returnsHTTP 200,0.0695edit 1 ref 1024x1024returnsHTTP 200,0.1edit 1 ref 1280x720returnsHTTP 200,0.094edit 3 refs 1024x1024returnsHTTP 200,0.2edit 1 ref 4032x3024returnsHTTP 200,0.6315edit 1 ref 8000x6000returnsHTTP 200,2.339edit 2 refs 4032x3024 + 640x640returnsHTTP 200,0.15flux-flex-override, 1 ref 4032x3024returnsHTTP 200,1.986527232flux-flex-zeroref, 1 ref 4032x3024returnsHTTP 200, no cost header (the image endpoints already omit a zero cost header)Every After number is
rate * 2^20 * (input_mp + output_mp)for Azure's measurement of that callType
🐛 Bug Fix
Caveats (if any)
Medium
Low
x-litellm-response-costwhen the cost is exactly 0Final Attestation
Link to Devin session: https://app.devin.ai/sessions/70b30e9f289d49e08561526f9110a933
Open in Devin Desktop: https://app.devin.ai/desktop/session/70b30e9f289d49e08561526f9110a933?variant=devin
Requested by: @shreshth-berri
Note
Medium Risk
Changes spend calculation and proxy cost headers for Azure FLUX.2 only, with fallback when request_meta is absent; incorrect parsing would mis-bill budgets and chargeback.
Overview
Azure AI FLUX.2 image generation and edits were undercounting spend because LiteLLM priced mostly from output dimensions and ignored reference-image megapixels Azure bills separately.
Responses now parse
request_meta.input_mpandoutput_mp, store the sum onImageResponse.provider_billed_megapixels, and the Azure AI cost path chargesinput_cost_per_pixel × 2²⁰ × (input_mp + output_mp)when that metadata is valid. Invalid or missing metadata keeps the previous dimension-based pixel pricing.The FLUX.2-flex catalog
input_cost_per_pixelis adjusted so one megapixel matches Azure’s $0.05/MP (using 1,048,576 pixels per MP). Proxy image edits merge deploymentCustomPricingLiteLLMParams(e.g. overrideinput_cost_per_pixel) into pre-call logging so spend headers and logs respect deployment rates. Azure image generation routing applies the FLUX.2 response transformer where needed.Reviewed by Cursor Bugbot for commit 3608ba3. Bugbot is set up for automated code reviews on this repo. Configure here.