{"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":"exception","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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/black_forest_labs/image_generation/transformation.py#L119-L155","documentation":"BFL's transformation maps the OpenAI size string to explicit width/height. Known presets are looked up first; otherwise the string is split on 'x' and both halves parsed with int(). If the split yields non-integer parts (or not exactly two), this ValueError is raised. Note the sibling gap: a size string with no 'x' at all (e.g. 'large') is silently ignored and BFL defaults are used — this error only fires when 'x' is present but parsing fails.","triggerScenarios":"size='1024' (missing height), size='1024x' , size='axb', size='1024x1024x768' (three parts -> ValueError from unpacking), size='1e3x1024' (non-decimal digits). All reach the split branch because they are not in the preset mapping.","commonSituations":"Building size dynamically ('f'{w}x{h}' with an empty or None height); passing DALL-E shorthand like 'auto', 'large', or 'hd' (silently ignored, not this error — but confusing); locale-formatted numbers ('1,024x1,024').","solutions":["Use the exact 'WIDTHxHEIGHT' decimal format, e.g. '1024x1024'.","Prefer preset strings already in the mapping (1024x1024, etc.) to skip parsing entirely.","Validate/construct size with a regex before calling so a bad value never reaches the mapper."],"exampleFix":"# before\nlitellm.image_generation(\n    model=\"black_forest_labs/flux-pro-1.1\",\n    prompt=\"a cat\",\n    size=f\"{width}x{height}\",  # height accidentally '' -> ValueError\n)\n\n# after\nassert isinstance(width, int) and isinstance(height, int)\nlitellm.image_generation(\n    model=\"black_forest_labs/flux-pro-1.1\",\n    prompt=\"a cat\",\n    size=f\"{width}x{height}\",\n)","handlingStrategy":"validation","validationCode":"import re\n\nSIZE_RE = re.compile(r\"^\\d+x\\d+$\")\n\ndef valid_size(size: str) -> bool:\n    return bool(SIZE_RE.match(size)) and all(0 < int(p) <= 4096 for p in size.lower().split(\"x\"))","typeGuard":"def is_valid_bfl_size(size: object) -> bool:\n    return (\n        isinstance(size, str)\n        and \"x\" in size.lower()\n        and len(size.lower().split(\"x\")) == 2\n        and all(p.isdigit() for p in size.lower().split(\"x\"))\n    )","tryCatchPattern":"try:\n    litellm.image_generation(model=\"black_forest_labs/flux-pro-1.1\", prompt=p, size=size)\nexcept ValueError as e:\n    if \"Invalid size format\" in str(e):\n        size = \"1024x1024\"  # safe fallback preset\n        litellm.image_generation(model=\"black_forest_labs/flux-pro-1.1\", prompt=p, size=size)\n    else:\n        raise","preventionTips":["Always build size as f\"{int(width)}x{int(height)}\" from validated integers.","Prefer preset sizes from the built-in mapping.","Remember strings without 'x' are silently ignored, not validated — check for typos like 'auto'."],"tags":["bfl","image-generation","size","validation","valueerror"],"backgroundTag":"invalid-argument-format","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}