BerriAI/litellm · error · ValueError

Error transforming text to image params: {e}. Got params: {t

Error message

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

What it means

For Nova Canvas TEXT_IMAGE generation, LiteLLM merges config and optional params into textToImageParams and validates them against the AmazonNovaCanvasTextToImageParams TypedDict/dataclass. Any constructor exception (missing required 'text', unknown key, wrong type) is re-raised as ValueError including the offending params and the expected annotations.

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 6c2dcb801b)

Solutions

  1. Read the error tail: Expected params lists the accepted keys — remove/rename the ones flagged in Got params.
  2. Ensure 'text' is a non-empty string and nested textToImageParams contains only supported keys (text, negativeText, plus allowed image refs per the TypedDict).
  3. Pass top-level OpenAI params (n, size, etc.) normally; let litellm map them into imageGenerationConfig rather than nesting them yourself.

Example fix

# before
litellm.image(model="bedrock/amazon.nova-canvas-v1:0",
             task="TEXT_IMAGE", prompt="a sunset",
             textToImageParams={"Text": "a sunset"})  # wrong casing -> ValueError
# after
litellm.image(model="bedrock/amazon.nova-canvas-v1:0",
             task="TEXT_IMAGE", prompt="a sunset")
# params flow automatically; use exact snake/camel keys litellm documents
Defensive patterns

Strategy: validation

Validate before calling

ALLOWED_T2I = {"text", "negativeText", "images"}  # per AmazonNovaCanvasTextToImageParams

def valid_t2i_params(p: dict) -> bool:
    return set(p) <= ALLOWED_T2I and isinstance(p.get("text"), str) and p["text"] != ""

Type guard

def is_valid_text_to_image_params(p: object) -> bool:
    return (
        isinstance(p, dict)
        and isinstance(p.get("text"), str)
        and p["text"].strip() != ""
    )

Prevention

When it happens

Trigger: litellm.image(model='bedrock/nova-canvas...', task='TEXT_IMAGE') with an invalid key inside textToImageParams (e.g. passing images/colors there), a non-string text, or text missing after an empty prompt; keys with wrong casing ('Text' instead of 'text').

Common situations: Hand-building textToImageParams dicts from AWS docs examples with wrong casing; forwarding arbitrary user kwargs into optional_params; prompt passed as None/empty so 'text' key ends up invalid.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/836792ce720780de. Report an issue: GitHub.