Gateway: guard base64 image size accounting

This commit is contained in:
Vincent Koc
2026-03-06 00:57:57 -05:00
parent 298f9a4f60
commit c3f4250442

View File

@@ -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})`,