BerriAI/litellm · error · BlackForestLabsError
Error parsing BFL response: {e}
Error message
Error parsing BFL response: {e} What it means
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.
Source
Thrown at litellm/llms/black_forest_labs/image_edit/transformation.py:297
# BFL uses JSON, not multipart - return empty files
return request_body, []
def transform_image_edit_response(
self,
model: str,
raw_response: httpx.Response,
logging_obj: LiteLLMLoggingObj,
) -> ImageResponse:
"""
Transform Black Forest Labs response to OpenAI-compatible ImageResponse.
This is called with the FINAL polled response (after handler does polling).
The response contains: {"status": "Ready", "result": {"sample": "https://..."}}
"""
try:
response_data: Final = raw_response.json()
except Exception as e:
raise BlackForestLabsError(
status_code=raw_response.status_code,
message=f"Error parsing BFL response: {e}",
)
# Get image URL from result
image_url: Final = response_data.get("result", {}).get("sample")
if not image_url:
raise BlackForestLabsError(
status_code=500,
message="No image URL in BFL result",
)
# Build ImageResponse
return ImageResponse(
created=int(time.time()),
data=[ImageObject(url=image_url)],
)
View on GitHub (pinned to 6c2dcb801b)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
from litellm.exceptions import APIError
try:
resp = await litellm.aimage_edit(model=M, image=img, prompt=p)
except APIError as e:
if "Error parsing BFL response" in str(e):
log.warning("BFL returned non-JSON final body; retrying once")
return await litellm.aimage_edit(model=M, image=img, prompt=p)
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Error parsing initial response: {e}
- Error parsing BFL response: {e}
- Error in response object format, got None
- No image URL in BFL result
- Invalid JSON response: {raw_response.text}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/1b2738ad577d6832.
Report an issue: GitHub.