Repository navigation
fix(azure_ai): bill FLUX.2-flex edit reference images by megapixel - #42822
Draft
shreshth-berri wants to merge 6 commits into
Draft
shreshth-berri wants to merge 6 commits into
shreshth-berri wants to merge 6 commits into
Conversation
added 4 commits
September 23, 2026 13:30
The Flex row stored 0.05 / 1,000,000 per pixel, so a 1024x1024 image billed 0.0524288 instead of 0.05. Azure and Black Forest Labs define one megapixel as 1,048,576 pixels, so the rate is 0.05 / 1048576, exact in float64. Tests that pinned the old literal now derive the rate from the catalog and assert the invariant our code owns: one 1024x1024 image prices at exactly one megapixel
…_image_dimensions get_image_dimensions fetched or decoded its input, parsed the header, and substituted a 300x300 default when the header was unreadable, all in one function. Billing code needs the middle step on its own: given bytes, return the dimensions or None, never a default. The parsers are unchanged and the string entry point still applies the default, so its callers see no difference. Unreadable headers used to raise TypeError or struct.error out of the parser; the bytes entry point turns those into None
Azure meters FLUX.2 image edits twice: once for the generated pixels and once for every pixel of the reference images sent with the edit. input_cost_per_pixel already means the generated image's pixels in default_image_cost_calculator, so the reference meter gets its own key. The Flex row carries it at the same 0.05 per 1024x1024 megapixel as its output rate, per the Azure retail prices API rows for 'Azure BFL Flux Models' (Flex Megapixel and Flex Ref Megapixel, checked 2026-09-23). Declared everywhere a deployment can set a price: the cost map and its regenerated schema, CustomPricingLiteLLMParams, the Rust catalog, the Terraform provider, and the dashboard's OpenAPI types
Azure meters a FLUX.2 edit for the pixels it generates and again for every pixel of the reference images sent with it. The proxy priced the generated image only, so an edit cost the same with one reference or three The Flux2 edit config already reads each reference's bytes to base64 them into the request. It now measures those same bytes with image_dimensions_from_bytes, sums the areas, and hands the total to the response as the reference_image_pixels hidden param. The azure_ai image cost calculator adds that count times input_cost_per_reference_pixel, resolving the rate the same way it resolves the generated-pixel rate: deployment pricing first, shared catalog second. A reference whose header cannot be read contributes zero pixels and the request goes ahead, so the fallback only ever under-bills. Provider-reported token usage still short-circuits everything. Flat-priced rows carry no reference rate, so their edits are unchanged
|
Shreshth Kharbanda seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Contributor
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…_flux2_reference_billing # Conflicts: # litellm-rust/crates/model-catalog/src/model_info.rs
Bill azure_ai/flux.2-pro edit references on Azure's Flux 2 Ref meter ($0.015 per 1024x1024 megapixel) so Pro edits stop logging the flat per-image price only Read seekable reference streams from offset 0 and rewind them after, so a router retry or fallback resends the full image instead of an empty input_image and bills its pixels again Bill a reference whose header cannot be parsed (bmp, tiff, heic, a truncated file) as one megapixel instead of zero, and log a warning Carry the deployment's custom pricing params into image edit logging so a proxy deployment's input_cost_per_pixel and input_cost_per_reference_pixel apply to /v1/images/edits the way they already do for generations
4 of 6 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Problem this solves:
How it solves it:
input_cost_per_reference_pixelrate on Flex and Pro/v1/images/editsIntentional product change:
azure_ai/FLUX.2-flexgenerations now log $0.05 per 1024x1024 megapixel instead of $0.0524288, matching Azure's meterUser Flow
Before: an admin sending FLUX.2 edits through the proxy sees spend far below the Azure invoice
model=azure_ai/FLUX.2-flex, one 1024x1024 reference,size=1024x1024x-litellm-response-cost: 0.0524288whatever the reference size isinput_cost_per_pixelstill logs the global rateAfter: the logged cost matches what Azure meters for the same edit
x-litellm-response-cost: 0.1(one generated plus one reference megapixel)flux.2-proedit adds $0.015 per reference megapixelLinear ticket
Resolves LIT-8140
Pre-Submission checklist
Screenshots / Proof of Fix
Shared setup: a proxy started with the config below, pointed at a local stand-in for the Azure BFL endpoint that answers with the same JSON shape and measures megapixels with PIL (independent of LiteLLM's parser). Live Azure runs are still to do, see Caveats
Each case runs
curl -s -D - http://localhost:4000/v1/images/edits -H "Authorization: Bearer $KEY" -F model=<group> -F prompt="make it blue" -F size=<size> -F "image[]=@<file>"and readsx-litellm-response-cost. The spend log'sresponse_costmatched the header on every request. Azure's bill uses the retail price API (productName eq 'Azure BFL Flux Models', Global Standard): Flex $0.05/MP, Flex Ref $0.05/MP, Flux 2 Pro Initial MP $0.03, Flux 2 Pro MP $0.015, Flux 2 Ref MP $0.015, with 1 MP = 1024x1024Before (d33d36c)
input_imageAfter (2fec04a)
Generations with no references: Flex 1024x1024 goes from 0.0524288 to 0.05 and 640x640 from 0.02048 to 0.01953125. Pro stays at 0.04 and the Data Zone deployment stays at 0.055. The 4032x3024 reference measuring 11.628 MP here agrees with the
request_meta.input_mpof 11.63 that Azure returned for the same size in the live run on #43094Type
🐛 Bug Fix
Caveats (if any)
Medium
Low
azure_ai/FLUX.1-Kontext-prohas no reference meter on Azure, so it stays flat0forinput_cost_per_reference_pixel, same> 0guard asinput_cost_per_pixelFinal Attestation