{"record":{"id":"a44d57d69587b0de","repo":"BerriAI/litellm","slug":"vertex-ai-imagen-image-edit-requires-at-least-one","errorCode":null,"errorMessage":"Vertex AI Imagen image edit requires at least one reference image.","messagePattern":"Vertex AI Imagen image edit requires at least one reference image\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/vertex_ai/image_edit/vertex_imagen_transformation.py","lineNumber":157,"sourceCode":"        if api_base:\n            base_url = api_base.rstrip(\"/\")\n        else:\n            base_url = get_vertex_base_url(vertex_location)\n\n        return f\"{base_url}/v1/projects/{vertex_project}/locations/{vertex_location}/publishers/google/models/{model_name}:predict\"\n\n    def transform_image_edit_request(\n        self,\n        model: str,\n        prompt: str | None,\n        image: FileTypes | None,\n        image_edit_optional_request_params: dict[str, Any],\n        litellm_params: GenericLiteLLMParams,\n        headers: dict,\n    ) -> tuple[dict[str, Any], RequestFiles | None]:\n        # Prepare reference images in the correct Imagen format\n        if image is None:\n            raise ValueError(\"Vertex AI Imagen image edit requires at least one reference image.\")\n        reference_images: Final = self._prepare_reference_images(image, image_edit_optional_request_params)\n        if not reference_images:\n            raise ValueError(\"Vertex AI Imagen image edit requires at least one reference image.\")\n\n        if prompt is None:\n            raise ValueError(\"Vertex AI Imagen image edit requires a prompt.\")\n\n        # Correct Imagen instances format\n        instances: Final = [{\"prompt\": prompt, \"referenceImages\": reference_images}]\n\n        # Extract OpenAI parameters and set sensible defaults for Vertex AI-specific parameters\n        sample_count: Final = image_edit_optional_request_params.get(\"sampleCount\", 1)\n        # Use sensible defaults for Vertex AI-specific parameters (not exposed to users)\n        edit_mode: Final = \"EDIT_MODE_INPAINT_INSERTION\"  # Default edit mode\n        base_steps: Final = 50  # Default number of steps\n\n        # Imagen parameters with correct structure\n        parameters: Final = {","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/image_edit/vertex_imagen_transformation.py#L139-L175","documentation":"Imagen image editing is reference-image driven: every request instance must contain at least one referenceImage (the source photo to edit). The transformer checks the image argument first and raises immediately when it is None, before any byte reading or prompt validation. This mirrors the API contract — unlike Gemini edit, Imagen edit cannot proceed with prompt-only input.","triggerScenarios":"litellm.image_edit(model='vertex_ai/imagen-3.0-capability-001', prompt='make it night') with the image kwarg omitted or explicitly None; calling through the OpenAI-compatible images/edits endpoint with no image file in the multipart form.","commonSituations":"Reusing Gemini-edit code paths (where the same call shape exists) against an Imagen model; multipart proxy routes that forward an empty file field; API clients built against OpenAI where image is validated lazily.","solutions":["Always pass the source image (bytes, BytesIO, binary file object, or list of them) when the model is a vertex_ai/imagen-* edit model","Validate presence at the request boundary: reject requests without an image before they reach litellm","If no source image exists, switch to litellm.image_generation (prompt-only) instead of image_edit"],"exampleFix":"# before\nresp = litellm.image_edit(\n    model='vertex_ai/imagen-3.0-capability-001',\n    prompt='make it night',\n)  # image omitted -> raises\n\n# after\nwith open('street.png', 'rb') as f:\n    resp = litellm.image_edit(\n        model='vertex_ai/imagen-3.0-capability-001',\n        prompt='make it night',\n        image=f.read(),\n    )","handlingStrategy":"validation","validationCode":"if image is None:\n    raise ValueError('an edit request requires the source image')\n# then call litellm.image_edit(..., image=image, prompt=prompt)","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.image_edit(model='vertex_ai/imagen-3.0-capability-001', prompt=p, image=image)\nexcept ValueError as e:\n    if 'requires at least one reference image' in str(e):\n        return bad_request('source image is required for imagen edit')\n    raise","preventionTips":["Treat the image field as required for imagen-* edit models in your request models","Validate multipart uploads contain a non-empty file before proxying to litellm","Keep a mapping of which models need reference images and enforce it at the router layer"],"tags":["vertex-ai","imagen","image-edit","input-validation","missing-parameter"],"backgroundTag":"missing-required-parameter","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}