{"record":{"id":"0e6f0830c877e235","repo":"calesthio/OpenMontage","slug":"image-too-large-len-raw-bytes-max-6mb-raw","errorCode":null,"errorMessage":"Image too large ({len(raw)} bytes). Max ~6MB raw.","messagePattern":"Image too large \\((.+?) bytes\\)\\. Max ~6MB raw\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/graphics/hunyuan_image.py","lineNumber":401,"sourceCode":"        Per upstream docs: single image 50-5000px per side, base64 < 6MB.\n        Formats: jpg/jpeg/png/bmp/tiff/webp.\n        \"\"\"\n        import base64\n\n        resolved: list[str] = []\n        for ref in refs:\n            if ref.startswith(\"data:\") or ref.startswith(\"http://\") or ref.startswith(\"https://\"):\n                resolved.append(ref)\n                continue\n\n            image_path = Path(ref)\n            if not image_path.is_file():\n                raise FileNotFoundError(f\"Reference image not found: {ref}\")\n\n            raw = image_path.read_bytes()\n            max_raw = 6 * 1024 * 1024  # 6MB per upstream limit\n            if len(raw) > max_raw:\n                raise ValueError(\n                    f\"Image too large ({len(raw)} bytes). Max ~6MB raw.\"\n                )\n\n            suffix = image_path.suffix.lower()\n            mime_map = {\n                \".jpg\": \"image/jpeg\",\n                \".jpeg\": \"image/jpeg\",\n                \".png\": \"image/png\",\n                \".bmp\": \"image/bmp\",\n                \".tiff\": \"image/tiff\",\n                \".tif\": \"image/tiff\",\n                \".webp\": \"image/webp\",\n            }\n            mime = mime_map.get(suffix, \"image/png\")\n            data = base64.b64encode(raw).decode(\"ascii\")\n            resolved.append(f\"data:{mime};base64,{data}\")\n        return resolved\n","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/graphics/hunyuan_image.py#L383-L419","documentation":"ValueError from the Hunyuan reference-image resolver enforcing the upstream TokenHub API limit of roughly 6 MB per raw image file. The resolver reads the local file's bytes and rejects anything larger before base64 encoding, because encoding would inflate it further past the API cap.","triggerScenarios":"Passing a high-resolution local reference image (e.g. a 12 MB camera photo or lossless PNG screenshot) as a reference to the Hunyuan image tool.","commonSituations":"Modern phone photos and 4K screenshots routinely exceed 6 MB; users re-using print-quality assets; PNG exports from design tools that avoid compression.","solutions":["Downscale or recompress the image (JPEG quality ~85, longest side ~2048px) before passing it as a reference","Strip EXIF and metadata, which can add significant size","If the image must stay local and large, host it and pass an https:// URL instead — the resolver skips the size check for URLs","Batch-check all references in a loop so one oversized file fails fast before the API call"],"exampleFix":"# before\nrefs = [\"hero_raw.png\"]  # 9 MB\n# after\nfrom PIL import Image\nimg = Image.open(\"hero_raw.png\")\nimg.thumbnail((2048, 2048))\nimg.convert(\"RGB\").save(\"hero_ref.jpg\", \"JPEG\", quality=85)\nrefs = [\"hero_ref.jpg\"]","handlingStrategy":"validation","validationCode":"from pathlib import Path\nMAX_RAW = 6 * 1024 * 1024\nfor ref in refs:\n    if not ref.startswith((\"data:\", \"http://\", \"https://\")):\n        assert Path(ref).stat().st_size <= MAX_RAW, f\"{ref} exceeds 6MB raw limit\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize a downscale/compress step (max ~2048px, JPEG q85) for every local reference","Prefer hosted URLs for large references","Check sizes for all references up front so a batch fails before any API spend"],"tags":["hunyuan","reference-image","size-limit","validation"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}