{"record":{"id":"bae4b21672821db8","repo":"can1357/oh-my-pi","slug":"image-file-too-large-formatbytes-inputbytes-e","errorCode":null,"errorMessage":"Image file too large: ${formatBytes(inputBytes)} exceeds ${formatBytes(options.maxBytes)} limit.","messagePattern":"Image file too large: (.+?) exceeds (.+?) limit\\.","errorType":"validation","errorClass":"ImageInputTooLargeError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/utils/image-loading.ts","lineNumber":292,"sourceCode":"\t\treturn null;\n\t} catch (error) {\n\t\treturn error instanceof Error ? error.message : String(error);\n\t}\n}\n\ninterface LoadInMemoryImageInputOptions {\n\timage: ImageContent;\n\tresolvedPath: string;\n\ttextNotePrefix: string;\n\tautoResize: boolean;\n\tmaxBytes: number;\n\texcludeWebP: boolean | undefined;\n}\n\nasync function loadInMemoryImageInput(options: LoadInMemoryImageInputOptions): Promise<LoadedImageInput> {\n\tconst inputBytes = Buffer.byteLength(options.image.data, \"base64\");\n\tif (inputBytes > options.maxBytes) {\n\t\tthrow new ImageInputTooLargeError(inputBytes, options.maxBytes);\n\t}\n\n\t// Decode before anything else: a payload that cannot be decoded is rejected\n\t// by the provider for the whole request, so it must fail here — where the\n\t// caller still has a path to act on — instead of entering the transcript.\n\tconst decodeFailure = await imageDecodeFailureReason(options.image);\n\tif (decodeFailure !== null) {\n\t\tthrow new InvalidImageDataError(options.resolvedPath, options.image.mimeType, decodeFailure);\n\t}\n\n\tlet outputData = options.image.data;\n\tlet outputMimeType = options.image.mimeType;\n\tlet outputBytes = inputBytes;\n\tlet dimensionNote: string | undefined;\n\n\tconst shouldReencodeWebP = options.excludeWebP === true && options.image.mimeType === \"image/webp\";\n\tif (options.autoResize || shouldReencodeWebP) {\n\t\ttry {","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/utils/image-loading.ts#L274-L310","documentation":"loadInMemoryImageInput measures the base64 image payload size and throws ImageInputTooLargeError before decoding, so oversized images never enter the model transcript where the provider would reject the whole request.","triggerScenarios":"Passing image content whose base64 data exceeds options.maxBytes to loadInMemoryImageInput — reached via loadImageInput, loadSvgImageInput, or loadImageAttachmentInput when a file or attachment is over the configured byte limit.","commonSituations":"Attaching screenshots or camera photos several MB large; a caller configured with a small maxBytes; sending SVG or PNG exports from design tools without compression.","solutions":["Compress or downscale the image before passing it so it fits maxBytes.","Raise the maxBytes option at the call site if the limit is too strict for your workflow.","Convert to a more compact format (JPEG/WebP) or strip metadata to reduce bytes.","Check the file size first with fs.stat and surface a friendly message before attempting the load."],"exampleFix":"// before: await loadImageInput(path, { maxBytes: 100_000 }); // 3MB screenshot  // after: compress/downscale to a small JPEG, then await loadImageInput(path, { maxBytes: 100_000 });","handlingStrategy":"validation","validationCode":"const bytes = Buffer.byteLength(base64, \"base64\"); if (bytes > maxBytes) throw new Error(`image is ${bytes} bytes, limit is ${maxBytes}`);","typeGuard":null,"tryCatchPattern":"try { const img = await loadImageInput(path, { maxBytes }); } catch (err) { if (err instanceof ImageInputTooLargeError) { return resizeAndRetry(path, maxBytes); } throw err; }","preventionTips":["Stat the file before attaching images and downscale anything over the limit.","Prefer JPEG for photos; export PNGs at capped dimensions.","Pass an explicit maxBytes matching your provider's limits instead of relying on defaults.","Handle ImageInputTooLargeError with a resize-and-retry path."],"tags":["image","size-limit","validation"],"backgroundTag":"file-too-large","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}