{"record":{"id":"5b6f759de3f78266","repo":"BerriAI/litellm","slug":"error-parsing-bfl-response-e-5b6f75","errorCode":null,"errorMessage":"Error parsing BFL response: {e}","messagePattern":"Error parsing BFL response: (.+?)","errorType":"exception","errorClass":"BlackForestLabsError","httpStatus":null,"severity":"error","filePath":"litellm/llms/black_forest_labs/image_generation/transformation.py","lineNumber":272,"sourceCode":"        model_response: ImageResponse,\n        logging_obj: LiteLLMLoggingObj,\n        request_data: dict,\n        optional_params: dict,\n        litellm_params: dict,\n        encoding: Any,\n        api_key: str | None = None,\n        json_mode: bool | None = None,\n    ) -> ImageResponse:\n        \"\"\"\n        Transform Black Forest Labs response to OpenAI-compatible ImageResponse.\n\n        This is called with the FINAL polled response (after handler does polling).\n        The response contains: {\"status\": \"Ready\", \"result\": {\"sample\": \"https://...\"}}\n        \"\"\"\n        try:\n            response_data: Final = raw_response.json()\n        except Exception as e:\n            raise BlackForestLabsError(\n                status_code=raw_response.status_code,\n                message=f\"Error parsing BFL response: {e}\",\n            )\n\n        result: Final = response_data.get(\"result\", {})\n\n        if not model_response.data:\n            model_response.data = []\n\n        # Handle single image (sample) or multiple images\n        if isinstance(result, dict) and \"sample\" in result:\n            model_response.data.append(ImageObject(url=result[\"sample\"]))\n        elif isinstance(result, list):\n            # Multiple images returned\n            for img in result:\n                if isinstance(img, str):\n                    model_response.data.append(ImageObject(url=img))\n                elif isinstance(img, dict) and \"url\" in img:","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/black_forest_labs/image_generation/transformation.py#L254-L290","documentation":"transform_response calls raw_response.json() on the final polled BFL response (the one with status 'Ready'). If the body is not valid JSON — HTML error page, empty body, truncated payload — the exception is caught and re-raised as BlackForestLabsError carrying the HTTP status code and the parser error text. It indicates the response transport/shape is broken, not that generation failed.","triggerScenarios":"The polling endpoint returns 200 but a non-JSON body (HTML maintenance page, empty string), or a proxy/CDN truncates or rewrites the JSON; json.JSONDecodeError (or any parsing exception) is raised inside the try block.","commonSituations":"BFL gateway serving an HTML 200 error page during incidents; response body gzip/encoding corruption via middleboxes; mock/test servers returning plain text; very large result payloads cut off by proxy buffering limits.","solutions":["Inspect the exception's embedded parser message and, if possible, log raw_response.text[:500] to see the actual body.","Retry the request — transient gateway corruption is the most common cause.","If a proxy sits in front, bypass or fix it (buffering/timeout/rewrite rules).","Check BFL status during incidents; open a litellm issue if the body is JSON but a schema change broke parsing."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = client.transform_response(...)  # or images.generate\nexcept BlackForestLabsError as e:\n    if \"Error parsing BFL response\" in str(e):\n        logger.warning(\"BFL returned unparseable body (status %s); retrying\", e.status_code)\n        return retry_with_backoff()\n    raise","preventionTips":["Enable debug logging of raw response bodies when integrating BFL.","Keep proxies between you and BFL minimal; disable response rewriting.","Treat parse failures as transient first, persistent second (then file an issue)."],"tags":["bfl","json","response-parsing","proxy"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}