Skip to content

Commit 1a8dca2

Browse files
fix: Update API version and payload for dall-e-3 image generation
2 parents 86b86ba + c52964d commit 1a8dca2

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

content-gen/src/backend/orchestrator.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,14 @@ async def _generate_foundry_image(self, image_prompt: str, results: dict) -> Non
12451245

12461246
# The direct image API endpoint
12471247
image_api_url = f"{image_endpoint}/openai/deployments/{image_deployment}/images/generations"
1248-
api_version = app_settings.azure_openai.image_api_version or "2025-04-01-preview"
1248+
1249+
# Adapt API version and payload to the deployed image model
1250+
is_dalle3 = image_deployment.lower().startswith("dall-e")
1251+
1252+
if is_dalle3:
1253+
api_version = app_settings.azure_openai.preview_api_version or "2024-02-01"
1254+
else:
1255+
api_version = app_settings.azure_openai.image_api_version or "2025-04-01-preview"
12491256

12501257
logger.info(f"Calling Foundry direct image API: {image_api_url}")
12511258
logger.info(f"Prompt: {image_prompt[:200]}...")
@@ -1255,13 +1262,24 @@ async def _generate_foundry_image(self, image_prompt: str, results: dict) -> Non
12551262
"Content-Type": "application/json",
12561263
}
12571264

1258-
# gpt-image-1 parameters (no response_format parameter)
1259-
payload = {
1260-
"prompt": image_prompt,
1261-
"n": 1,
1262-
"size": "1024x1024",
1263-
"quality": "medium", # gpt-image-1 uses low/medium/high/auto
1264-
}
1265+
# Build model-appropriate payload
1266+
if is_dalle3:
1267+
# dall-e-3: quality must be "standard" or "hd"; needs response_format; 4000-char prompt limit
1268+
payload = {
1269+
"prompt": image_prompt[:4000],
1270+
"n": 1,
1271+
"size": app_settings.azure_openai.image_size or "1024x1024",
1272+
"quality": app_settings.azure_openai.image_quality or "hd",
1273+
"response_format": "b64_json",
1274+
}
1275+
else:
1276+
# gpt-image-1 / gpt-image-1.5: quality is low/medium/high/auto; no response_format
1277+
payload = {
1278+
"prompt": image_prompt,
1279+
"n": 1,
1280+
"size": "1024x1024",
1281+
"quality": "medium",
1282+
}
12651283

12661284
async with httpx.AsyncClient(timeout=120.0) as client:
12671285
response = await client.post(

0 commit comments

Comments
 (0)