Skip to content

Commit d9e4eaa

Browse files
committed
Fix MAI image generation base model routing
1 parent e08d51f commit d9e4eaa

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

litellm/llms/azure/azure.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,10 @@ def make_sync_azure_httpx_request(
11001100
)
11011101

11021102
def create_azure_base_url(
1103-
self, azure_client_params: dict, model: Optional[str]
1103+
self,
1104+
azure_client_params: dict,
1105+
model: Optional[str],
1106+
base_model: Optional[str] = None,
11041107
) -> str:
11051108
from litellm.llms.azure_ai.image_generation import (
11061109
AzureFoundryFluxImageGenerationConfig,
@@ -1116,8 +1119,7 @@ def create_azure_base_url(
11161119
if model is None:
11171120
model = ""
11181121

1119-
# MAI image models: /mai/v1/images/generations (serverless Azure AI)
1120-
if AzureFoundryMAIImageGenerationConfig.is_mai_model(model):
1122+
if AzureFoundryMAIImageGenerationConfig.is_mai_model(base_model or model):
11211123
return AzureFoundryMAIImageGenerationConfig.get_mai_image_generation_url(
11221124
api_base=api_base,
11231125
api_version=api_version,
@@ -1164,10 +1166,10 @@ async def aimage_generation(
11641166
if api_base.endswith("/"):
11651167
api_base = api_base.rstrip("/")
11661168
api_version: str = azure_client_params.get("api_version", "")
1167-
# Use the deployment name (model) for URL construction, not the base_model from data
11681169
img_gen_api_base = self.create_azure_base_url(
11691170
azure_client_params=azure_client_params,
11701171
model=model or data.get("model", ""),
1172+
base_model=data.get("model", ""),
11711173
)
11721174

11731175
## LOGGING
@@ -1296,9 +1298,10 @@ def image_generation(
12961298
if aimg_generation is True:
12971299
return self.aimage_generation(data=data, input=input, logging_obj=logging_obj, model_response=model_response, api_key=api_key, client=client, azure_client_params=azure_client_params, timeout=timeout, headers=headers, model=model) # type: ignore
12981300

1299-
# Use the deployment name (model) for URL construction, not the base_model from data
13001301
img_gen_api_base = self.create_azure_base_url(
1301-
azure_client_params=azure_client_params, model=model
1302+
azure_client_params=azure_client_params,
1303+
model=model,
1304+
base_model=base_model,
13021305
)
13031306

13041307
## LOGGING

tests/test_litellm/llms/azure/image_generation/test_azure_image_generation_init.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ def test_azure_providers_image_generation_json_body_keeps_model():
5757
assert out == data
5858

5959

60+
def test_azure_image_generation_mai_base_model_uses_mai_url():
61+
azure_chat = AzureChatCompletion()
62+
url = azure_chat.create_azure_base_url(
63+
azure_client_params={
64+
"azure_endpoint": "https://my-resource.services.ai.azure.com",
65+
"api_version": "preview",
66+
},
67+
model="image-deployment-alias",
68+
base_model="MAI-Image-2.5",
69+
)
70+
assert (
71+
url
72+
== "https://my-resource.services.ai.azure.com/mai/v1/images/generations?api-version=preview"
73+
)
74+
75+
6076
def test_azure_image_generation_flattens_extra_body():
6177
"""
6278
Test that Azure image generation correctly flattens extra_body parameters.

0 commit comments

Comments
 (0)