BerriAI/litellm · error · ValueError

Error transforming image generation config

Error message

Error transforming image generation config: {e}. Got params: {image_generation_config}, Expected params: {AmazonNovaCanvasImageGenerationConfig.__annotations__}

What it means

For a TEXT_IMAGE generation request the remaining imageGenerationConfig dict is validated by constructing AmazonNovaCanvasImageGenerationConfig(**config); unknown keys raise TypeError ('unexpected keyword argument') which LiteLLM wraps in this ValueError with the raw dict and expected annotations. Annotated keys: cfgScale, seed, quality ('standard'|'premium'), width, height, numberOfImages.

Solutions

  1. Keep imageGenerationConfig to annotated camelCase keys: cfgScale, seed, quality ('standard'|'premium'), width, height, numberOfImages
  2. Strip provider-specific kwargs before calling litellm.image for bedrock models
  3. Set drop_params=True so unsupported extras are dropped instead of failing
  4. Read the 'Got params' section of the message to find the offending key, then move it to the correct section or remove it

Example fix

# before
resp = litellm.image(
    model="bedrock/amazon.nova-canvas-v1:0",
    prompt="a red house",
    quality="hd",            # not a Nova Canvas config key value/shape
    response_format="b64_json",
)

# after
resp = litellm.image(
    model="bedrock/amazon.nova-canvas-v1:0",
    prompt="a red house",
    quality="premium",       # valid Nova Canvas enum
    width=1024,
    height=1024,
)
Defensive patterns

Strategy: validation

Validate before calling

from litellm.types.llms.bedrock import AmazonNovaCanvasImageGenerationConfig

def validate_generation_config(cfg: dict) -> None:
    allowed = set(AmazonNovaCanvasImageGenerationConfig.__annotations__)
    stray = set(cfg) - allowed
    assert not stray, f"unknown imageGenerationConfig keys: {stray}; allowed: {sorted(allowed)}"
    assert cfg.get("quality", "standard") in ("standard", "premium")

validate_generation_config(image_generation_config)

Type guard

def is_valid_nova_generation_config(cfg: dict) -> bool:
    """True when config keys match the TypedDict and quality is a valid enum."""
    from litellm.types.llms.bedrock import AmazonNovaCanvasImageGenerationConfig
    allowed = set(AmazonNovaCanvasImageGenerationConfig.__annotations__)
    return set(cfg) <= allowed and cfg.get("quality", "standard") in ("standard", "premium")

Try / catch

try:
    resp = litellm.image(...)
except ValueError as e:
    if "Error transforming image generation config" in str(e):
        log.exception("bad imageGenerationConfig")
        raise UserInputError("Check nova canvas config keys/values") from e
    raise

Prevention

When it happens

Trigger: Extra keys left in the generation config after popping task params — e.g. passing response_format, style, or output_compression via litellm.image optional params so they merge into imageGenerationConfig; misspelled 'cfg_scale' instead of 'cfgScale'.

Common situations: Forwarding OpenAI image kwargs to Nova Canvas unfiltered; snake_case/camelCase confusion when translating AWS examples; params meant for the proxy (like user) leaking into the typed dict.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at litellm/llms/bedrock/image_generation/amazon_nova_canvas_transformation.py:88

        # Extract model_id parameter to prevent "extraneous key" error from Bedrock API
        # Following the same pattern as chat completions and embeddings
        unencoded_model_id: Final = optional_params.pop("model_id", None)  # noqa: F841

        image_generation_config = {**image_generation_config, **optional_params}
        if task_type == "TEXT_IMAGE":
            text_to_image_params: dict[str, Any] = image_generation_config.pop("textToImageParams", {})
            text_to_image_params = {"text": text, **text_to_image_params}
            try:
                text_to_image_params_typed: Final = AmazonNovaCanvasTextToImageParams(**text_to_image_params)
            except Exception as e:
                raise ValueError(
                    f"Error transforming text to image params: {e}. Got params: {text_to_image_params}, Expected params: {AmazonNovaCanvasTextToImageParams.__annotations__}"
                )

            try:
                image_generation_config_typed = AmazonNovaCanvasImageGenerationConfig(**image_generation_config)
            except Exception as e:
                raise ValueError(
                    f"Error transforming image generation config: {e}. Got params: {image_generation_config}, Expected params: {AmazonNovaCanvasImageGenerationConfig.__annotations__}"
                )

            return AmazonNovaCanvasTextToImageRequest(
                textToImageParams=text_to_image_params_typed,
                taskType=task_type,
                imageGenerationConfig=image_generation_config_typed,
            )
        if task_type == "COLOR_GUIDED_GENERATION":
            color_guided_generation_params: dict[str, Any] = image_generation_config.pop(
                "colorGuidedGenerationParams", {}
            )
            color_guided_generation_params = {
                "text": text,
                **color_guided_generation_params,
            }
            try:
                color_guided_generation_params_typed: Final = AmazonNovaCanvasColorGuidedGenerationParams(

View on GitHub (pinned to 77b7c6c40c)