BerriAI/litellm · error · ValueError

Error transforming text to image params

Error message

Error transforming text to image params: {e}. Got params: {text_to_image_params}, Expected params: {AmazonNovaCanvasTextToImageParams.__annotations__}

What it means

When building a Nova Canvas TEXT_IMAGE generation request, LiteLLM constructs AmazonNovaCanvasTextToImageParams(**params) from the merged textToImageParams (with 'text' injected). Because that model is a TypedDict, unknown keys surface as TypeError ('unexpected keyword argument'), which LiteLLM wraps in this ValueError along with the offending dict and the expected annotations. Valid keys: text, negativeText, controlStrength, controlMode, conditionImage.

Solutions

  1. Use only the annotated camelCase keys: text, negativeText, controlStrength, controlMode ('CANNY_EDIT'|'SEGMENTATION'), conditionImage (base64)
  2. Put generation knobs (width, height, quality, cfgScale, seed, numberOfImages) in imageGenerationConfig, not textToImageParams
  3. Upgrade LiteLLM if AWS added a new field to textToImageParams
  4. Log the 'Got params' portion of the message — it shows exactly which key failed

Example fix

# before
resp = litellm.image(
    model="bedrock/amazon.nova-canvas-v1:0",
    prompt="a red house",
    negative_text="blurry",          # wrong key shape
)

# after
resp = litellm.image(
    model="bedrock/amazon.nova-canvas-v1:0",
    prompt="a red house",
    textToImageParams={"negativeText": "blurry"},
)
Defensive patterns

Strategy: validation

Validate before calling

from litellm.types.llms.bedrock import AmazonNovaCanvasTextToImageParams

def validate_text_to_image_params(p: dict) -> None:
    allowed = set(AmazonNovaCanvasTextToImageParams.__annotations__)
    stray = set(p) - allowed
    assert not stray, f"unknown textToImageParams keys: {stray}; allowed: {sorted(allowed)}"

validate_text_to_image_params(text_to_image_params)

Type guard

def is_valid_text_to_image_params(p: dict) -> bool:
    """True when every key matches AmazonNovaCanvasTextToImageParams annotations."""
    from litellm.types.llms.bedrock import AmazonNovaCanvasTextToImageParams
    allowed = set(AmazonNovaCanvasTextToImageParams.__annotations__)
    return set(p) <= allowed

Try / catch

try:
    resp = litellm.image(...)
except ValueError as e:
    if "Error transforming text to image params" in str(e):
        log.exception("bad textToImageParams")
        raise UserInputError("Check nova canvas text params keys") from e
    raise

Prevention

When it happens

Trigger: litellm.image(model='bedrock/amazon.nova-canvas-v1:0', ...) with an extra/misspelled key routed into textToImageParams, e.g. 'negative_text' instead of 'negativeText', or passing a generation knob like 'width' inside the params dict.

Common situations: Translating AWS SDK examples to LiteLLM with snake_case keys; version drift where AWS ships new textToImageParams fields before LiteLLM's TypedDict knows them; generically forwarding user-supplied dicts as optional params.

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/836792ce720780de. Report an issue: GitHub.

Appendix: source

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

    def transform_request_body(cls, text: str, optional_params: dict) -> AmazonNovaCanvasRequestBase:
        """
        Transform the request body for Amazon Nova Canvas model
        """
        task_type: Final = optional_params.pop("taskType", "TEXT_IMAGE")
        image_generation_config = optional_params.pop("imageGenerationConfig", {})

        # 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", {}

View on GitHub (pinned to 77b7c6c40c)