Add Azure AI MAI image generation support - #27061
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Greptile SummaryAdds Azure AI MAI image generation support ( Confidence Score: 5/5Safe to merge — no functional bugs found, all prior review concerns resolved. No P0 or P1 findings. The routing logic, cost calculation, dimension validation, and header handling are all correct. The No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/azure_ai/image_generation/mai_transformation.py | New MAI transformation class with URL construction, request/response mapping, and dimension validation — clean implementation with good error handling |
| litellm/llms/azure_ai/image_generation/init.py | Refactored to metadata-driven routing via _supports_mai_endpoint using get_model_info + model_cost lookup; normalization is now consistent via _normalize_model_name |
| litellm/llms/azure_ai/image_generation/cost_calculator.py | Extended to support token-based pricing with usage-first calculation that falls back to per-image pricing; math is correct for both MAI models |
| litellm/images/main.py | Added MAI routing branch that dispatches to llm_http_handler when config is AzureFoundryMAIImageGenerationConfig; both extra_headers and headers kwargs are correctly forwarded |
| tests/test_litellm/llms/azure_ai/image_generation/test_azure_ai_mai_image_generation_metadata.py | New test file covering model metadata, cost calculation, config selection, request mapping, and HTTP routing — all mock-only, no real network calls |
Reviews (2): Last reviewed commit: "Break Azure AI image cost import cycle" | Re-trigger Greptile
There was a problem hiding this comment.
Pull request overview
Adds Azure AI Foundry “MAI-Image-2” / “MAI-Image-2e” image generation support to LiteLLM, including catalog metadata, request routing to the MAI-specific endpoint, and token-based image cost calculation.
Changes:
- Add MAI model entries (pricing + modalities + endpoints) to the model cost maps and validate via new metadata/cost tests.
- Introduce an Azure Foundry MAI image-generation provider config that transforms
size→width/heightand targets/mai/v1/images/generations. - Extend Azure AI image cost calculation to prefer usage/token-based computation when usage metadata is present.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_litellm/llms/azure_ai/image_generation/test_azure_ai_mai_image_generation_metadata.py | Adds tests for MAI metadata, cost calculation, request mapping, and routing behavior. |
| model_prices_and_context_window.json | Registers azure_ai/MAI-Image-2 and azure_ai/MAI-Image-2e with token-based output pricing metadata. |
| litellm/model_prices_and_context_window_backup.json | Mirrors the MAI entries for the packaged/local cost map used in tests. |
| litellm/llms/azure_ai/image_generation/mai_transformation.py | New MAI request/response transformation + URL builder for the Foundry MAI endpoint. |
| litellm/llms/azure_ai/image_generation/cost_calculator.py | Uses usage-based cost calculation when available, otherwise falls back to per-image pricing. |
| litellm/llms/azure_ai/image_generation/init.py | Routes MAI model names to the new MAI image generation config. |
| litellm/images/main.py | Routes Azure AI MAI image generation through llm_http_handler.image_generation_handler. |
| litellm/types/llms/openai.py | Extends the image generation optional-param typing to include width/height. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Closing due to partially superseed by #29688 |
Summary
MAI-Image-2andMAI-Image-2ewith verified pricing, modalities, and support metadata/mai/v1/images/generationswith MAI-specific request transformation forsize/width/heightTesting
uv run black litellm/llms/azure_ai/image_generation/mai_transformation.py litellm/llms/azure_ai/image_generation/__init__.py litellm/images/main.py litellm/types/llms/openai.py tests/test_litellm/llms/azure_ai/image_generation/test_azure_ai_mai_image_generation_metadata.pyuv run pytest tests/test_litellm/llms/azure_ai/image_generation/test_azure_ai_mai_image_generation_metadata.py tests/test_litellm/images/test_image_generation_extra_headers.py -qlitellm.image_generation()calls against both Azure AI MAI deployments (MAI-Image-2,MAI-Image-2e) via the Foundry MAI endpoint