can1357/oh-my-pi · error

Image file too large: ${imagePath}

Error message

Image file too large: ${imagePath}

What it means

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.

Source

Thrown at packages/coding-agent/src/tools/image-gen.ts:787

		case "antigravity":
			return modelRegistry ? findAntigravityCredentials(modelRegistry, sessionId) : null;
		case "xai":
			return findXAIImageCredentials(modelRegistry);
		case "openrouter":
			return findOpenRouterImageCredentials(modelRegistry, sessionId);
		case "deepinfra":
			return findDeepInfraImageCredentials(modelRegistry, sessionId);
		case "gemini":
			return findGeminiImageCredentials(modelRegistry, sessionId);
	}
}

async function loadImageFromPath(imagePath: string, cwd: string): Promise<InlineImageData> {
	const resolved = resolveReadPath(imagePath, cwd);
	try {
		const buffer = await Bun.file(resolved).bytes();
		if (buffer.length > MAX_IMAGE_SIZE) {
			throw new Error(`Image file too large: ${imagePath}`);
		}

		const metadata = parseImageMetadata(buffer);
		const mimeType = metadata?.mimeType;
		if (!mimeType) {
			throw new Error(`Unsupported image type: ${imagePath}`);
		}

		return { data: buffer.toBase64(), mimeType };
	} catch (err) {
		if (isEnoent(err)) throw new Error(`Image file not found: ${imagePath}`);
		throw err;
	}
}

async function resolveInputImage(input: ImageInput, cwd: string): Promise<InlineImageData> {
	if (input.path) {
		return loadImageFromPath(input.path, cwd);

View on GitHub (pinned to 9690622007)

Solutions

  1. Resize/re-encode the image (e.g. `magick input.png -resize 2048x2048 output.png`) below the size cap
  2. Convert lossless PNG to JPEG/WebP to shrink it dramatically
  3. Crop to the region of interest instead of sending the full frame
  4. Reference the image by URL or process it in chunks if the workflow allows

Example fix

// shell
magick big.png -define jpeg:quality=80 big.jpg  # re-encode under cap
// tool call
"image": "big.jpg"  // instead of big.png
Defensive patterns

Strategy: validation

Validate before calling

import * as fs from "node:fs";
function checkImageSize(path: string, maxBytes = 5 * 1024 * 1024): void {
	const size = fs.statSync(path).size;
	if (size > maxBytes) throw new Error(`Image file too large: ${path} (${size} bytes)`);
}

Try / catch

try {
	await genImage({ image: imagePath });
} catch (err) {
	if (err instanceof Error && err.message.startsWith("Image file too large:")) {
		// shrink and retry
	}
	throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: Camera originals or screenshots at retina resolution; PNG screenshots that should be JPEG; large marketing assets passed whole instead of resized.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/f633c5a38d58d653. Report an issue: GitHub.