{"record":{"id":"95847fe8dd5d5254","repo":"Comfy-Org/ComfyUI","slug":"image-limit-must-be-greater-than-or-equal-to-0-whe","errorCode":null,"errorMessage":"image_limit must be greater than or equal to 0 when creating Gemini image parts.","messagePattern":"image_limit must be greater than or equal to 0 when creating Gemini image parts\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_gemini.py","lineNumber":95,"sourceCode":"      $r := widgets.resolution;\n      $isFlash := $contains($m, \"nano banana 2\");\n      $flashPrices := {\"1k\": 0.0835, \"2k\": 0.1217, \"4k\": 0.1848};\n      $proPrices := {\"1k\": 0.1608, \"2k\": 0.1608, \"4k\": 0.288};\n      $prices := $isFlash ? $flashPrices : $proPrices;\n      {\"type\":\"usd\",\"usd\": $lookup($prices, $r), \"format\":{\"suffix\":\"/Image\",\"approximate\":true}}\n    )\n    \"\"\",\n)\n\n\nasync def create_image_parts(\n    cls: type[IO.ComfyNode],\n    images: Input.Image | list[Input.Image],\n    image_limit: int = 0,\n) -> list[GeminiPart]:\n    image_parts: list[GeminiPart] = []\n    if image_limit < 0:\n        raise ValueError(\"image_limit must be greater than or equal to 0 when creating Gemini image parts.\")\n\n    # Accept either a single (possibly-batched) tensor or a list of them; share URL budget across all.\n    images_list: list[Input.Image] = images if isinstance(images, list) else [images]\n    total_images = sum(get_number_of_images(img) for img in images_list)\n    if total_images <= 0:\n        raise ValueError(\"No images provided to create_image_parts; at least one image is required.\")\n\n    # If image_limit == 0 --> use all images; otherwise clamp to image_limit.\n    effective_max = total_images if image_limit == 0 else min(total_images, image_limit)\n\n    # Number of images we'll send as URLs (fileData)\n    num_url_images = min(effective_max, 10)  # Vertex API max number of image links\n    upload_kwargs: dict = {\"wait_label\": \"Uploading reference images\"}\n    if effective_max > num_url_images:\n        # Split path (e.g. 11+ images): suppress per-image counter to avoid a confusing dual-fraction label.\n        upload_kwargs = {\n            \"wait_label\": f\"Uploading reference images ({num_url_images}+)\",\n            \"show_batch_index\": False,","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_gemini.py#L77-L113","documentation":"Raised by create_image_parts() in nodes_gemini.py when the image_limit argument is negative. image_limit == 0 means 'use all images'; positive values clamp the count; negative values are a programming error in the calling node, not user configuration.","triggerScenarios":"A Gemini node passes image_limit < 0 to create_image_parts — i.e. a widget value or code path supplying a negative limit where only 0 (unlimited) or a positive cap is meaningful.","commonSituations":"Custom nodes or modified workflows calling create_image_parts with a computed limit that underflows; an upstream numeric widget holding a negative value; copy-paste from code where -1 meant 'all'.","solutions":["Pass 0 to send all images, or a positive integer to cap the count.","If the limit is computed, clamp it: max(0, computed_limit).","Check the calling node's widget for a negative number and correct it."],"exampleFix":"// before: parts = await create_image_parts(cls, images, image_limit=-1)\n// after:  parts = await create_image_parts(cls, images, image_limit=0)  # 0 = use all images","handlingStrategy":"validation","validationCode":"def normalize_image_limit(limit: int) -> int:\n    if limit < 0:\n        raise ValueError(\"image_limit must be >= 0\")\n    return limit\n\n# or simply: limit = max(0, limit) if -1 was meant as 'all'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 0 for 'all images', never -1.","Clamp computed limits before passing them into create_image_parts."],"tags":["comfyui","gemini","validation","programmer-error","api-usage"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}