BerriAI/litellm · error · ValueError

data field is required, for openai image variations. Got=

Error message

data field is required, for openai image variations. Got={data}

What it means

After the image-variation provider config transforms the request, litellm expects a dict containing a 'data' payload to send; if transform_request_image_variation returns a dict without a truthy 'data' field, this ValueError is raised with the returned dict echoed back. It indicates the request-transform step produced an unusable payload - an internal contract violation between the handler and the provider config.

Solutions

  1. Ensure the image argument is a valid, readable file (open in binary mode, non-empty PNG/JPEG) before the call
  2. If you override transform_request_image_variation, return {'data': <json-dict>, 'files': <list>} exactly - the handler requires the 'data' key
  3. Reproduce with the plain OpenAI dall-e-2 path (no custom config); if it works, the defect is in your custom transform; if not, upgrade litellm / file an issue
  4. Upgrade litellm - the transform contract and its error handling have evolved across versions

Example fix

# before (custom config violating the contract)
class MyConfig(OpenAIImageVariationConfig):
    def transform_request_image_variation(self, **kwargs):
        return {"files": ["img.png"]}  # missing "data" -> ValueError

# after
class MyConfig(OpenAIImageVariationConfig):
    def transform_request_image_variation(self, model, image, optional_params, headers):
        data, files = super().transform_request_image_variation(
            model=model, image=image, optional_params=optional_params, headers=headers
        )
        return {"data": data, "files": files}  # contract satisfied
Defensive patterns

Strategy: validation

Validate before calling

import os

# ensure the input yields actual bytes before transforming
def variation_input_ok(path: str) -> bool:
    return os.path.exists(path) and os.path.getsize(path) > 0

assert variation_input_ok("cat.png"), "image missing/empty - transform would return no data"

with open("cat.png", "rb") as img:  # keep the file OPEN through the call
    resp = litellm.image_variations(image=img, model="dall-e-2")

Type guard

def transform_result_valid(result) -> bool:
    """A variation transform result must carry a truthy 'data' payload."""
    return isinstance(result, dict) and bool(result.get("data"))

Try / catch

try:
    resp = litellm.image_variations(image=open("cat.png", "rb"), model="dall-e-2")
except ValueError as e:
    if "data field is required" in str(e):
        # input/transform issue: retry once with a freshly-opened binary handle
        with open("cat.png", "rb") as img:
            resp = litellm.image_variations(image=img, model="dall-e-2")
    else:
        raise

Prevention

When it happens

Trigger: Calling litellm.image_variations() where the provider config's transform_request_image_variation fails to build the multipart/json payload - e.g. a malformed image input that defeats encoding, optional_params/metadata configurations that make the transform return only files and no data dict, or a custom/overridden variation config whose transform method does not implement the {'data': ..., 'files': ...} contract.

Common situations: Subclassing or monkey-patching variation configs and returning the wrong shape; passing unusual file-like objects (SpooledTemporaryFile edge cases, 0-byte reads) so the transform silently produces nothing; version drift where the transform contract changed but a local override did not.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/6ca5db2f085c6d8e. Report an issue: GitHub.

Appendix: source

Thrown at litellm/llms/openai/image_variations/handler.py:149

            provider_config: Final = ProviderConfigManager.get_provider_image_variation_config(
                model=model or "",  # openai defaults to dall-e-2
                provider=LlmProviders.OPENAI,
            )

            if provider_config is None:
                raise ValueError(f"image variation provider not found: {custom_llm_provider}.")

            max_retries: Final = optional_params.pop("max_retries", 2)

            data: Final = provider_config.transform_request_image_variation(
                model=model,
                image=image,
                optional_params=optional_params,
                headers=headers or {},
            )
            json_data: Final = data.get("data")
            if not json_data:
                raise ValueError(f"data field is required, for openai image variations. Got={data}")
            ## LOGGING
            logging_obj.pre_call(
                input="",
                api_key=api_key,
                additional_args={
                    "headers": headers,
                    "api_base": api_base,
                    "complete_input_dict": data,
                },
            )
            if litellm_params.get("async_call", False):
                return self.async_image_variations(
                    api_base=api_base,
                    data=json_data,
                    headers=headers or {},
                    model_response=model_response,
                    api_key=api_key,
                    logging_obj=logging_obj,

View on GitHub (pinned to 77b7c6c40c)