{"record":{"id":"f633c5a38d58d653","repo":"can1357/oh-my-pi","slug":"image-file-too-large-imagepath","errorCode":null,"errorMessage":"Image file too large: ${imagePath}","messagePattern":"Image file too large: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/image-gen.ts","lineNumber":787,"sourceCode":"\t\tcase \"antigravity\":\n\t\t\treturn modelRegistry ? findAntigravityCredentials(modelRegistry, sessionId) : null;\n\t\tcase \"xai\":\n\t\t\treturn findXAIImageCredentials(modelRegistry);\n\t\tcase \"openrouter\":\n\t\t\treturn findOpenRouterImageCredentials(modelRegistry, sessionId);\n\t\tcase \"deepinfra\":\n\t\t\treturn findDeepInfraImageCredentials(modelRegistry, sessionId);\n\t\tcase \"gemini\":\n\t\t\treturn findGeminiImageCredentials(modelRegistry, sessionId);\n\t}\n}\n\nasync function loadImageFromPath(imagePath: string, cwd: string): Promise<InlineImageData> {\n\tconst resolved = resolveReadPath(imagePath, cwd);\n\ttry {\n\t\tconst buffer = await Bun.file(resolved).bytes();\n\t\tif (buffer.length > MAX_IMAGE_SIZE) {\n\t\t\tthrow new Error(`Image file too large: ${imagePath}`);\n\t\t}\n\n\t\tconst metadata = parseImageMetadata(buffer);\n\t\tconst mimeType = metadata?.mimeType;\n\t\tif (!mimeType) {\n\t\t\tthrow new Error(`Unsupported image type: ${imagePath}`);\n\t\t}\n\n\t\treturn { data: buffer.toBase64(), mimeType };\n\t} catch (err) {\n\t\tif (isEnoent(err)) throw new Error(`Image file not found: ${imagePath}`);\n\t\tthrow err;\n\t}\n}\n\nasync function resolveInputImage(input: ImageInput, cwd: string): Promise<InlineImageData> {\n\tif (input.path) {\n\t\treturn loadImageFromPath(input.path, cwd);","sourceCodeStart":769,"sourceCodeEnd":805,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/image-gen.ts#L769-L805","documentation":"Inline images read from disk must not exceed MAX_IMAGE_SIZE bytes; larger files are rejected because providers cap inline image payloads and the tool base64-encodes them (inflating size ~33%). The error names the offending path so the user knows which file to shrink or link differently.","triggerScenarios":"resolveInputImage → loadImageFromPath reads a file whose byte length exceeds MAX_IMAGE_SIZE — e.g. supplying a 12MB scanned PNG or high-res JPEG as an input image to image generation.","commonSituations":"Camera originals or screenshots at retina resolution; PNG screenshots that should be JPEG; large marketing assets passed whole instead of resized.","solutions":["Resize/re-encode the image (e.g. `magick input.png -resize 2048x2048 output.png`) below the size cap","Convert lossless PNG to JPEG/WebP to shrink it dramatically","Crop to the region of interest instead of sending the full frame","Reference the image by URL or process it in chunks if the workflow allows"],"exampleFix":"// shell\nmagick big.png -define jpeg:quality=80 big.jpg  # re-encode under cap\n// tool call\n\"image\": \"big.jpg\"  // instead of big.png","handlingStrategy":"validation","validationCode":"import * as fs from \"node:fs\";\nfunction checkImageSize(path: string, maxBytes = 5 * 1024 * 1024): void {\n\tconst size = fs.statSync(path).size;\n\tif (size > maxBytes) throw new Error(`Image file too large: ${path} (${size} bytes)`);\n}","typeGuard":null,"tryCatchPattern":"try {\n\tawait genImage({ image: imagePath });\n} catch (err) {\n\tif (err instanceof Error && err.message.startsWith(\"Image file too large:\")) {\n\t\t// shrink and retry\n\t}\n\tthrow err;\n}","preventionTips":["Pre-resize screenshots/photos to ≤2048px before passing them in","Prefer JPEG/WebP for large photos over PNG","Check file size with stat before invoking the tool in automated pipelines","Crop to the relevant region instead of sending full-frame assets"],"tags":["validation","file-size","image-generation","input-image"],"backgroundTag":"image-file-too-large","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}