From c3f4250442efd2d44feb37aca1a65cc0195d16be Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 6 Mar 2026 00:57:57 -0500 Subject: [PATCH] Gateway: guard base64 image size accounting --- src/gateway/openai-http.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gateway/openai-http.ts b/src/gateway/openai-http.ts index 1f37dfb1fae..8e255d92764 100644 --- a/src/gateway/openai-http.ts +++ b/src/gateway/openai-http.ts @@ -300,7 +300,11 @@ async function resolveImagesForRequest( for (const url of urls) { const source = parseImageUrlToSource(url); if (source.type === "base64") { - totalBytes += estimateBase64DecodedBytes(source.data); + const base64Data = source.data; + if (typeof base64Data !== "string") { + throw new Error("image_url data URI is missing payload data"); + } + totalBytes += estimateBase64DecodedBytes(base64Data); if (totalBytes > limits.maxTotalImageBytes) { throw new Error( `Total image payload too large (${totalBytes}; limit ${limits.maxTotalImageBytes})`,