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
- 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
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
- 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
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
- Error transforming color guided generation params
- Error transforming image generation config
- Error transforming inpainting params
- Task type is not supported
- Amazon Nova Canvas INPAINTING requires either maskPrompt or…
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)