{"record":{"id":"1b2738ad577d6832","repo":"BerriAI/litellm","slug":"error-parsing-bfl-response-e","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_edit/transformation.py","lineNumber":297,"sourceCode":"        # BFL uses JSON, not multipart - return empty files\n        return request_body, []\n\n    def transform_image_edit_response(\n        self,\n        model: str,\n        raw_response: httpx.Response,\n        logging_obj: LiteLLMLoggingObj,\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        # Get image URL from result\n        image_url: Final = response_data.get(\"result\", {}).get(\"sample\")\n        if not image_url:\n            raise BlackForestLabsError(\n                status_code=500,\n                message=\"No image URL in BFL result\",\n            )\n\n        # Build ImageResponse\n        return ImageResponse(\n            created=int(time.time()),\n            data=[ImageObject(url=image_url)],\n        )\n","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/black_forest_labs/image_edit/transformation.py#L279-L315","documentation":"After the edit job finishes polling, the handler transforms the final polled response. This error means raw_response.json() threw — the HTTP body was not valid JSON (or the response object was already consumed/closed). The exception's text is embedded in the message. The reported status_code mirrors the raw response's status code, which can be 200 even though the body was HTML/garbage.","triggerScenarios":"The final poll of the BFL polling_url returns a non-JSON body (HTML error page from a gateway, truncated body from a dropped connection, empty body), or a proxy/interceptor rewrites the response.","commonSituations":"Corporate proxies or middleboxes returning HTML auth pages; BFL gateway edge incidents serving error pages with 200; response body truncation on flaky connections; custom api_base pointing at a non-BFL endpoint that replies in a different format.","solutions":["Inspect the raw body: log response.text in a retry to see what actually came back (HTML page, empty, partial JSON).","If a proxy is in play, bypass it for *.bfl.ai or configure it to pass JSON through unmodified.","Verify api_base — it should be the real BFL endpoint, not a gateway with a different response schema.","Retry once; transient gateway pages usually resolve."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"from litellm.exceptions import APIError\n\ntry:\n    resp = await litellm.aimage_edit(model=M, image=img, prompt=p)\nexcept APIError as e:\n    if \"Error parsing BFL response\" in str(e):\n        log.warning(\"BFL returned non-JSON final body; retrying once\")\n        return await litellm.aimage_edit(model=M, image=img, prompt=p)\n    raise","preventionTips":["Log full response bodies on transform failures to identify proxy interference.","Exclude bfl.ai from corporate proxies/TLS inspection.","Pin a known-good api_base instead of environment overrides."],"tags":["bfl","json","response-parsing","proxy","image-edit"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}