{"record":{"id":"f49555bb974ed1f0","repo":"BerriAI/litellm","slug":"nova-canvas-image-edit-requires-an-image-input","errorCode":null,"errorMessage":"Nova Canvas image edit requires an image input","messagePattern":"Nova Canvas image edit requires an image input","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/bedrock/image_edit/amazon_nova_canvas_image_edit_transformation.py","lineNumber":134,"sourceCode":"        return {\"taskType\": \"INPAINTING\", \"inPaintingParams\": in_params}\n    var_params: Final[dict[str, Any]] = {\n        \"images\": [image_b64],\n        \"text\": text,\n    }\n    if negative_text is not None:\n        var_params[\"negativeText\"] = negative_text\n    if similarity_strength is not None:\n        var_params[\"similarityStrength\"] = similarity_strength\n    return {\n        \"taskType\": \"IMAGE_VARIATION\",\n        \"imageVariationParams\": var_params,\n    }\n\n\ndef _file_types_to_b64(image: FileTypes | None) -> str:\n    \"\"\"Encode OpenAI image input to base64 string for Nova Canvas.\"\"\"\n    if image is None:\n        raise ValueError(\"Nova Canvas image edit requires an image input\")\n    if hasattr(image, \"read\") and callable(getattr(image, \"read\", None)):\n        if hasattr(image, \"seek\"):\n            image.seek(0)\n        image_bytes: Final = image.read()\n        return base64.b64encode(image_bytes).decode(\"utf-8\")\n    if isinstance(image, bytes):\n        return base64.b64encode(image).decode(\"utf-8\")\n    if isinstance(image, str):\n        return image\n    if isinstance(image, os.PathLike):\n        with open(image, \"rb\") as f:\n            return base64.b64encode(f.read()).decode(\"utf-8\")\n    if isinstance(image, tuple):\n        raise ValueError(\n            \"Nova Canvas image edit does not support tuple FileTypes. \"\n            \"Pass a file-like object, bytes, or a base64-encoded string.\"\n        )\n    return base64.b64encode(bytes(image)).decode(\"utf-8\")","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/bedrock/image_edit/amazon_nova_canvas_image_edit_transformation.py#L116-L152","documentation":"Nova Canvas image edit on Bedrock is an edit API: it always needs a source image, encoded to base64 by _file_types_to_b64. That helper raises immediately when image is None (the handler also maps an empty image list to None via image[0] if image else None), before any request is built.","triggerScenarios":"litellm.image_edit(model='bedrock/amazon.nova-canvas-v1:0', prompt='a sunset') with image omitted or image=[]; the variable holding the file object is None because an earlier upload/open failed.","commonSituations":"Using image_edit for pure text-to-image generation (that is litellm.image()); optional-image code paths where the file may legitimately be absent; silent failures from open()/requests producing None.","solutions":["Pass the source image: image=open('cat.png', 'rb'), raw bytes, a base64 string, or a pathlib.Path","For text-to-image without an input image use litellm.image(model='bedrock/amazon.nova-canvas-v1:0', ...) instead","Assert image is not None before the call in code where the file is optional"],"exampleFix":"# before\nresp = litellm.image_edit(\n    model=\"bedrock/amazon.nova-canvas-v1:0\",\n    prompt=\"make the sky sunset-colored\",\n)\n\n# after\nresp = litellm.image_edit(\n    model=\"bedrock/amazon.nova-canvas-v1:0\",\n    image=open(\"scene.png\", \"rb\"),\n    prompt=\"make the sky sunset-colored\",\n)","handlingStrategy":"validation","validationCode":"def require_image(image):\n    if image is None:\n        raise ValueError(\"image_edit requires a source image; use litellm.image() for generation\")\n    return image\n\nimg = require_image(maybe_none_image)","typeGuard":"def is_supplied(image) -> bool:\n    \"\"\"True when a source image/mask value is present and non-empty.\"\"\"\n    if image is None:\n        return False\n    if isinstance(image, (list, tuple)):\n        return len(image) > 0\n    return True","tryCatchPattern":"try:\n    resp = litellm.image_edit(...)\nexcept ValueError as e:\n    if \"requires an image input\" in str(e):\n        raise UserInputError(\"Upload a source image to edit\") from e\n    raise","preventionTips":["Make the image argument required (positional) in your own wrapper so static checks catch omissions","Validate uploaded files exist and are readable before building the edit request","Reserve image_edit for edits; route text-to-image traffic to litellm.image()"],"tags":["bedrock","nova-canvas","image-edit","required-argument","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}