BerriAI/litellm · error · ValueError
Vertex AI Gemini image edit requires at least one image.
Error message
Vertex AI Gemini image edit requires at least one image.
What it means
The Vertex AI Gemini image-edit handler encodes every input image as an inlineData part inside the generateContent request. It refuses to build a request containing zero image parts: if image is None, falsy (e.g. b''), or a list whose entries are all None, inline_parts comes back empty and this ValueError is raised. Prompt-only edits are not supported through this path — that is image generation, not edit.
Source
Thrown at litellm/llms/vertex_ai/image_edit/vertex_gemini_transformation.py:157
if not vertex_project or not vertex_location:
raise ValueError("vertex_project and vertex_location are required for Vertex AI")
base_url: Final = get_vertex_base_url(vertex_location)
return f"{base_url}/v1/projects/{vertex_project}/locations/{vertex_location}/publishers/google/models/{model_name}:generateContent"
def transform_image_edit_request(
self,
model: str,
prompt: str | None,
image: FileTypes | None,
image_edit_optional_request_params: dict[str, Any],
litellm_params: GenericLiteLLMParams,
headers: dict,
) -> tuple[dict[str, Any], RequestFiles | None]:
inline_parts: Final = self._prepare_inline_image_parts(image) if image else []
if not inline_parts:
raise ValueError("Vertex AI Gemini image edit requires at least one image.")
# Build parts list with image and prompt (if provided)
parts: Final = inline_parts.copy()
if prompt is not None and prompt != "":
parts.append({"text": prompt})
# Correct format for Vertex AI Gemini image editing
contents: Final = {"role": "USER", "parts": parts}
request_body: Final[dict[str, Any]] = {"contents": contents}
# Generation config with proper structure for image editing
generation_config: Final[dict[str, Any]] = {"response_modalities": ["IMAGE"]}
# Add image-specific configuration
image_config: Final[dict[str, Any]] = {}
if "aspectRatio" in image_edit_optional_request_params:
image_config["aspect_ratio"] = image_edit_optional_request_params["aspectRatio"]View on GitHub (pinned to 77b7c6c40c)
Solutions
- Always pass at least one image as bytes, io.BytesIO, or a binary file object (open with 'rb')
- Filter None entries out of image lists before calling: image=[i for i in imgs if i is not None]
- If you have no input image, use litellm.image_generation(model='vertex_ai/imagen-...') instead of image_edit
Example fix
# before
resp = litellm.image_edit(
model='vertex_ai/gemini-2.5-flash-image',
prompt='add a hat',
image=None,
)
# after
with open('cat.png', 'rb') as f:
resp = litellm.image_edit(
model='vertex_ai/gemini-2.5-flash-image',
prompt='add a hat',
image=f,
) Defensive patterns
Strategy: validation
Validate before calling
def usable_images(image) -> bool:
if image is None or image == b'':
return False
if isinstance(image, (list, tuple)):
return any(img is not None and img != b'' for img in image)
return True
assert usable_images(image), 'Gemini image edit requires at least one image' Try / catch
try:
resp = litellm.image_edit(model='vertex_ai/gemini-2.5-flash-image', prompt=p, image=image)
except ValueError as e:
if 'requires at least one image' in str(e):
return bad_request('attach an image to edit')
raise Prevention
- Make the image field mandatory in your API schema for edit endpoints
- Filter None entries from image lists before calling litellm
- Route prompt-only requests to image_generation, not image_edit
When it happens
Trigger: litellm.image_edit(model='vertex_ai/gemini-...', prompt='make it snowy') with the image kwarg omitted or image=None; passing image=[None, None]; passing image=b'' (empty bytes are falsy so the prep step is skipped).
Common situations: Porting OpenAI images/edits workflows where the image was optional; upload pipelines that pass a list comprehension result which filtered everything out; UI code where the user submitted a prompt without attaching a photo.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- Unsupported image type for Vertex AI Gemini image edit.
- Vertex AI Imagen image edit requires at least one reference
- Vertex AI Imagen image edit requires a prompt.
- Gemini image edit requires at least one image.
- vertex_project and vertex_location are required for Vertex A
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/21f032d4dae0344d.
Report an issue: GitHub.