{"record":{"id":"3d1a6fa19e2ae063","repo":"calesthio/OpenMontage","slug":"image-too-large-len-raw-bytes-max-6mb-raw-3d1a6f","errorCode":null,"errorMessage":"Image too large ({len(raw)} bytes). Max ~6MB raw (8MB base64-encoded).","messagePattern":"Image too large \\((.+?) bytes\\)\\. Max ~6MB raw \\(8MB base64-encoded\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tools/video/hunyuan_cloud_video.py","lineNumber":394,"sourceCode":"        \"\"\"\n        if inputs.get(\"model\"):\n            return inputs[\"model\"]\n        operation = inputs.get(\"operation\", \"text_to_video\")\n        return _MODEL_I2V if operation == \"image_to_video\" else _MODEL_T2V\n\n    @staticmethod\n    def _encode_image(path: str) -> str:\n        \"\"\"Read a local image file and return a base64-encoded string.\"\"\"\n        import base64\n\n        image_path = Path(path)\n        if not image_path.is_file():\n            raise FileNotFoundError(f\"Image not found: {path}\")\n\n        raw = image_path.read_bytes()\n        max_raw = 6 * 1024 * 1024  # 6MB raw ≈ 8MB base64\n        if len(raw) > max_raw:\n            raise ValueError(\n                f\"Image too large ({len(raw)} bytes). Max ~6MB raw (8MB base64-encoded).\"\n            )\n\n        return base64.b64encode(raw).decode(\"ascii\")\n\n    # ------------------------------------------------------------------\n    # API communication (TokenHub OpenAI-compatible)\n    # ------------------------------------------------------------------\n\n    @staticmethod\n    def _auth_headers(api_key: str) -> dict[str, str]:\n        \"\"\"Build common request headers for TokenHub API calls.\"\"\"\n        return {\n            \"Authorization\": f\"Bearer {api_key}\",\n            \"Content-Type\": \"application/json\",\n        }\n\n    def _submit_task(","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/video/hunyuan_cloud_video.py#L376-L412","documentation":"Raised by _encode_image when the local image exceeds 6 MB raw (which base64-encodes to ~8 MB). The TokenHub endpoint is OpenAI-compatible and inlines the image as base64 in the JSON body, so the tool enforces a hard size cap to keep the request payload within API limits; oversized images raise ValueError instead of sending a doomed request.","triggerScenarios":"Calling hunyuan_cloud_video with operation='image_to_video' where the image file is larger than 6*1024*1024 bytes. Common with high-resolution PNGs, photos straight from a camera, or lossless exports.","commonSituations":"4K/8K PNG first frames; uncompressed TIFF/BMP exported from design tools; base64 inflation (x1.33) pushing an otherwise-acceptable 7 MB file over the endpoint's body limit.","solutions":["Compress/resize the image: convert to JPEG at quality ~85 and cap the longest side (e.g. 1920px), which almost always lands under 6 MB.","Strip unnecessary alpha channels/metadata (PNG → JPEG) before passing it in.","If the image must stay lossless, downscale resolution to reduce raw bytes below the cap."],"exampleFix":"# before\n{\"operation\": \"image_to_video\", \"image_path\": \"frame_4k.png\"}  # 18MB\n\n# after (shell)\nffmpeg -i frame_4k.png -vf scale=1920:-2 -q:v 3 frame.jpg\n# then\n{\"operation\": \"image_to_video\", \"image_path\": \"frame.jpg\"}","handlingStrategy":"validation","validationCode":"from pathlib import Path\nimport subprocess, tempfile\n\nMAX_RAW = 6 * 1024 * 1024\n\ndef ensure_image_under_cap(path: str) -> str:\n    p = Path(path)\n    if p.stat().st_size <= MAX_RAW:\n        return str(p)\n    out = Path(tempfile.mkdtemp()) / (p.stem + \".jpg\")\n    subprocess.run(\n        [\"ffmpeg\", \"-y\", \"-i\", str(p), \"-vf\", \"scale=1920:-2\", \"-q:v\", \"3\", str(out)],\n        check=True, capture_output=True,\n    )\n    if out.stat().st_size > MAX_RAW:\n        raise ValueError(f\"still too large after re-encode: {out.stat().st_size}\")\n    return str(out)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize first frames as JPEG ~q85 at <=1920px longest side.","Check file size in your glue code before invoking the tool.","Remember base64 inflates by ~4/3 — budget raw size at 6MB, not 8MB."],"tags":["hunyuan","tokenhub","image-size","base64","validation","payload-limit"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}