{"record":{"id":"836792ce720780de","repo":"BerriAI/litellm","slug":"error-transforming-text-to-image-params-e-got","errorCode":null,"errorMessage":"Error transforming text to image params: {e}. Got params: {text_to_image_params}, Expected params: {AmazonNovaCanvasTextToImageParams.__annotations__}","messagePattern":"Error transforming text to image params: (.+?)\\. Got params: (.+?), Expected params: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/bedrock/image_generation/amazon_nova_canvas_transformation.py","lineNumber":81,"sourceCode":"    def transform_request_body(cls, text: str, optional_params: dict) -> AmazonNovaCanvasRequestBase:\n        \"\"\"\n        Transform the request body for Amazon Nova Canvas model\n        \"\"\"\n        task_type: Final = optional_params.pop(\"taskType\", \"TEXT_IMAGE\")\n        image_generation_config = optional_params.pop(\"imageGenerationConfig\", {})\n\n        # Extract model_id parameter to prevent \"extraneous key\" error from Bedrock API\n        # Following the same pattern as chat completions and embeddings\n        unencoded_model_id: Final = optional_params.pop(\"model_id\", None)  # noqa: F841\n\n        image_generation_config = {**image_generation_config, **optional_params}\n        if task_type == \"TEXT_IMAGE\":\n            text_to_image_params: dict[str, Any] = image_generation_config.pop(\"textToImageParams\", {})\n            text_to_image_params = {\"text\": text, **text_to_image_params}\n            try:\n                text_to_image_params_typed: Final = AmazonNovaCanvasTextToImageParams(**text_to_image_params)\n            except Exception as e:\n                raise ValueError(\n                    f\"Error transforming text to image params: {e}. Got params: {text_to_image_params}, Expected params: {AmazonNovaCanvasTextToImageParams.__annotations__}\"\n                )\n\n            try:\n                image_generation_config_typed = AmazonNovaCanvasImageGenerationConfig(**image_generation_config)\n            except Exception as e:\n                raise ValueError(\n                    f\"Error transforming image generation config: {e}. Got params: {image_generation_config}, Expected params: {AmazonNovaCanvasImageGenerationConfig.__annotations__}\"\n                )\n\n            return AmazonNovaCanvasTextToImageRequest(\n                textToImageParams=text_to_image_params_typed,\n                taskType=task_type,\n                imageGenerationConfig=image_generation_config_typed,\n            )\n        if task_type == \"COLOR_GUIDED_GENERATION\":\n            color_guided_generation_params: dict[str, Any] = image_generation_config.pop(\n                \"colorGuidedGenerationParams\", {}","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/bedrock/image_generation/amazon_nova_canvas_transformation.py#L63-L99","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use only the annotated camelCase keys: text, negativeText, controlStrength, controlMode ('CANNY_EDIT'|'SEGMENTATION'), conditionImage (base64)","Put generation knobs (width, height, quality, cfgScale, seed, numberOfImages) in imageGenerationConfig, not textToImageParams","Upgrade LiteLLM if AWS added a new field to textToImageParams","Log the 'Got params' portion of the message — it shows exactly which key failed"],"exampleFix":"# before\nresp = litellm.image(\n    model=\"bedrock/amazon.nova-canvas-v1:0\",\n    prompt=\"a red house\",\n    negative_text=\"blurry\",          # wrong key shape\n)\n\n# after\nresp = litellm.image(\n    model=\"bedrock/amazon.nova-canvas-v1:0\",\n    prompt=\"a red house\",\n    textToImageParams={\"negativeText\": \"blurry\"},\n)","handlingStrategy":"validation","validationCode":"from litellm.types.llms.bedrock import AmazonNovaCanvasTextToImageParams\n\ndef validate_text_to_image_params(p: dict) -> None:\n    allowed = set(AmazonNovaCanvasTextToImageParams.__annotations__)\n    stray = set(p) - allowed\n    assert not stray, f\"unknown textToImageParams keys: {stray}; allowed: {sorted(allowed)}\"\n\nvalidate_text_to_image_params(text_to_image_params)","typeGuard":"def is_valid_text_to_image_params(p: dict) -> bool:\n    \"\"\"True when every key matches AmazonNovaCanvasTextToImageParams annotations.\"\"\"\n    from litellm.types.llms.bedrock import AmazonNovaCanvasTextToImageParams\n    allowed = set(AmazonNovaCanvasTextToImageParams.__annotations__)\n    return set(p) <= allowed","tryCatchPattern":"try:\n    resp = litellm.image(...)\nexcept ValueError as e:\n    if \"Error transforming text to image params\" in str(e):\n        log.exception(\"bad textToImageParams\")\n        raise UserInputError(\"Check nova canvas text params keys\") from e\n    raise","preventionTips":["Type your request builders against the TypedDict annotations instead of free-form dicts","Reject unvalidated user-supplied kwargs before they reach litellm.image","Watch LiteLLM release notes when AWS adds Nova Canvas fields"],"tags":["bedrock","nova-canvas","image-generation","typeddict","schema-validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}