fix(azure_ai): ignore non-finite FLUX.2 request_meta megapixels
Some checks failed
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
LiteLLM Rust / rust-wheel (push) Has been cancelled

This commit is contained in:
shrey kharbanda 2026-09-25 02:15:37 +00:00
parent 61a361abbf
commit 3608ba392e
2 changed files with 6 additions and 1 deletions

View file

@ -1,3 +1,4 @@
import math
from collections.abc import Mapping
from types import MappingProxyType
from typing import TYPE_CHECKING, Final
@ -42,7 +43,10 @@ def with_flux2_billed_megapixels(image_response: ImageResponse, raw_response: ht
request_meta: Final = _Flux2ResponseBody.model_validate_json(raw_response.content).request_meta
except ValidationError:
return image_response
image_response.set_provider_billed_megapixels(request_meta.input_mp + request_meta.output_mp)
billed_megapixels: Final = request_meta.input_mp + request_meta.output_mp
if not math.isfinite(billed_megapixels):
return image_response
image_response.set_provider_billed_megapixels(billed_megapixels)
return image_response

View file

@ -204,6 +204,7 @@ def test_flux2_cost_uses_mapped_dimensions_after_response_transformation(dimensi
({"input_mp": 45.78, "output_mp": 1.0}, 46.78),
({"output_mp": 0.39}, 2048 * 1024 / (1024 * 1024)),
({"input_mp": -1.0, "output_mp": 0.39}, 2048 * 1024 / (1024 * 1024)),
({"input_mp": 1.7e308, "output_mp": 1.7e308}, 2048 * 1024 / (1024 * 1024)),
),
)
def test_flux2_generation_bills_azure_reported_megapixels_and_falls_back_to_requested_size(