{"record":{"id":"151f8a516e1c7be7","repo":"BerriAI/litellm","slug":"invalid-size-format-size-expected-format-wi-151f8a","errorCode":null,"errorMessage":"Invalid size format: '{size}'. Expected format 'WIDTHxHEIGHT' (e.g., '1024x1024').","messagePattern":"Invalid size format: '(.+?)'\\. Expected format 'WIDTHxHEIGHT' \\(e\\.g\\., '1024x1024'\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/black_forest_labs/image_generation/transformation.py","lineNumber":137,"sourceCode":"            \"1024x1024\": (1024, 1024),\n            \"1792x1024\": (1792, 1024),\n            \"1024x1792\": (1024, 1792),\n            \"512x512\": (512, 512),\n            \"256x256\": (256, 256),\n        }\n\n        if size in size_mapping:\n            width, height = size_mapping[size]\n            optional_params[\"width\"] = width\n            optional_params[\"height\"] = height\n        elif \"x\" in size:\n            # Parse custom size\n            try:\n                width, height = map(int, size.lower().split(\"x\"))\n                optional_params[\"width\"] = width\n                optional_params[\"height\"] = height\n            except ValueError:\n                raise ValueError(f\"Invalid size format: '{size}'. Expected format 'WIDTHxHEIGHT' (e.g., '1024x1024').\")\n\n    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        messages: list[AllMessageValues],\n        optional_params: dict,\n        litellm_params: dict,\n        api_key: str | None = None,\n        api_base: str | None = None,\n    ) -> dict:\n        \"\"\"\n        Validate environment and set up headers for Black Forest Labs.\n\n        BFL uses x-key header for authentication.\n        \"\"\"\n        final_api_key: Final[str | None] = (\n            api_key or get_secret_str(\"BFL_API_KEY\") or get_secret_str(\"BLACK_FOREST_LABS_API_KEY\")","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/black_forest_labs/image_generation/transformation.py#L119-L155","documentation":"When mapping the OpenAI 'size' parameter, the handler first tries a lookup table of common sizes; otherwise it splits the string on 'x' and converts both halves to int. If that conversion raises ValueError (non-numeric component), this error is raised telling you the expected 'WIDTHxHEIGHT' format. Note the guard is partial: a size with no 'x' at all and not in the mapping is silently ignored, so only malformed 'WxH' strings with an 'x' raise.","triggerScenarios":"Passing size=\"512xABC\", size=\"1024-X\", size=\"1x2x3\" (map of 3 values to 2 names fails), or any '<something>x<non-integer>' to a BFL image generation call.","commonSituations":"Building size strings dynamically from user input (e.g. f\"{w}x{h}\" where w/h are empty or contain units like '1024px'); copy-paste sizes from other providers using '*' or '×' separators instead of 'x'; locale issues producing comma decimals.","solutions":["Send size as a literal 'WIDTHxHEIGHT' string of two integers, e.g. '1024x1024' or '1344x768'.","If sizes come from user input, validate with a regex like ^\\d+x\\d+$ before calling litellm.","Prefer the canonical sizes in the mapping table (1024x1024, etc.) to skip parsing entirely."],"exampleFix":"# before\nsize = f\"{width}px x {height}px\"\n\n# after\nimport re\nassert re.fullmatch(r\"\\d+x\\d+\", f\"{width}x{height}\"), \"size must be WxH\"\nsize = f\"{width}x{height}\"","handlingStrategy":"validation","validationCode":"import re\n\ndef is_valid_size(size: str) -> bool:\n    return bool(re.fullmatch(r\"\\d+x\\d+\", size))","typeGuard":"def is_valid_size(size: str) -> bool:\n    \"\"\"True when size is WIDTHxHEIGHT with integer components.\"\"\"\n    parts = size.lower().split(\"x\")\n    return len(parts) == 2 and all(p.isdigit() for p in parts)","tryCatchPattern":"try:\n    litellm.images.generate(model=\"bfl/flux-dev\", prompt=p, size=size)\nexcept ValueError as e:\n    if \"Invalid size format\" in str(e):\n        raise ValueError(f\"user-supplied size '{size}' rejected: use WxH\") from e\n    raise","preventionTips":["Validate user-provided sizes with ^\\d+x\\d+$ before calling.","Offer a fixed dropdown of canonical sizes in UIs.","Never include units ('px') or unicode '×' in size strings."],"tags":["bfl","size","validation","input-format"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}