perf: parallelize image loading in image_edits endpoint (#20911)

Use asyncio.gather() to load multiple images concurrently instead of
sequentially, significantly reducing latency for multi-image edit
operations.
This commit is contained in:
7. Sun
2026-01-27 20:35:25 +00:00
committed by GitHub
parent 2c12278444
commit 33020d826f

View File

@@ -910,7 +910,8 @@ async def image_edits(
if isinstance(form_data.image, str):
form_data.image = await load_url_image(form_data.image)
elif isinstance(form_data.image, list):
form_data.image = [await load_url_image(img) for img in form_data.image]
# Load all images in parallel for better performance
form_data.image = list(await asyncio.gather(*[load_url_image(img) for img in form_data.image]))
except Exception as e:
raise HTTPException(status_code=400, detail=ERROR_MESSAGES.DEFAULT(e))