BerriAI/litellm · error · BlackForestLabsError

Error parsing initial response: {e}

Error message

Error parsing initial response: {e}

What it means

The sync submission returned a status < 400, but its body could not be parsed as JSON when the handler looked for the polling_url. The parse exception is embedded in the message and the status code mirrors the original response. Typically a 2xx/3xx response carrying HTML or garbage instead of the expected JSON job envelope.

Source

Thrown at litellm/llms/black_forest_labs/image_generation/handler.py:310

        max_wait: float = DEFAULT_MAX_POLLING_TIME,
        interval: float = DEFAULT_POLLING_INTERVAL,
        timeout: float | httpx.Timeout | None = None,
    ) -> httpx.Response:
        """
        Poll BFL API until result is ready (sync version).
        """
        # Validate initial response status code
        if initial_response.status_code >= 400:
            raise BlackForestLabsError(
                status_code=initial_response.status_code,
                message=f"BFL initial request failed: {initial_response.text}",
            )

        # Parse initial response to get polling URL
        try:
            response_data: Final = initial_response.json()
        except Exception as e:
            raise BlackForestLabsError(
                status_code=initial_response.status_code,
                message=f"Error parsing initial response: {e}",
            )

        # Check for immediate errors
        if "errors" in response_data:
            raise BlackForestLabsError(
                status_code=initial_response.status_code,
                message=f"BFL error: {response_data['errors']}",
            )

        polling_url: Final = response_data.get("polling_url")
        if not polling_url:
            raise BlackForestLabsError(
                status_code=500,
                message="No polling_url in BFL response",
            )

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Log the raw response body (response.text) on failure to identify what answered (HTML page, empty, error JSON).
  2. Verify api_base in your config equals the genuine BFL base URL.
  3. Bypass or correctly configure proxies for bfl.ai traffic.
  4. Retry once; load-balancer misroutes are usually intermittent.
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

try:
    img = litellm.image_generation(model=M, prompt=p)
except Exception as e:
    if "Error parsing initial response" in str(e):
        log_body_and_probe_network()  # proxy/misroute diagnosis, then retry once
        return litellm.image_generation(model=M, prompt=p)
    raise

Prevention

When it happens

Trigger: BFL (or an intermediary) answers the submission POST with a non-JSON body: captive-portal/proxy HTML pages, a 200 empty body from a misrouted load balancer, or a custom api_base whose endpoint does not return the BFL job schema.

Common situations: Corporate proxies intercepting HTTPS to api.bfl.ai; wrong api_base configured in litellm_params pointing at a status page or incompatible gateway; truncated responses on unstable links.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/40d35d856bc99cbc. Report an issue: GitHub.