BerriAI/litellm · error · BlackForestLabsError

Request failed

Error message

Request failed: {e}

What it means

The synchronous BFL image-generation handler wraps the initial `POST` (to the generation endpoint) in try/except; any exception the HTTP client raises before a response exists - DNS failure, connection refused, TLS error, timeout - is re-raised as `BlackForestLabsError(status_code=500, message="Request failed: {e}")`. The 500 is synthetic: it reflects a client-side transport failure, not an HTTP status from BFL.

Solutions

  1. Read the embedded exception text after 'Request failed:' - 'connect timeout', 'Name or service not known', 'certificate verify failed' each point to different fixes.
  2. Verify egress: `curl -I https://api.bfl.ai` from the same host/container.
  3. Set proxy env vars (HTTPS_PROXY) if a corporate proxy is required, or pass litellm-level proxy/timeout params to increase the timeout.
  4. If the base_url was customized, check it resolves and serves the BFL endpoints.
Defensive patterns

Strategy: retry

Validate before calling

import socket, ssl, urllib.request

def bfl_reachable(host: str = "api.bfl.ai", timeout: float = 5.0) -> bool:
    try:
        urllib.request.urlopen(f"https://{host}/", timeout=timeout)
    except urllib.error.HTTPError:
        return True   # got an HTTP response -> reachable
    except (URLError, socket.timeout, ssl.SSLError, ConnectionError):
        return False

assert bfl_reachable(), "no egress to api.bfl.ai - fix proxy/DNS before calling litellm"

Try / catch

from litellm.llms.black_forest_labs.common_utils import BlackForestLabsError

try:
    resp = litellm.image_generation(model="flux-pro-1.1", prompt=p)
except BlackForestLabsError as e:
    if e.status_code == 500 and str(e).startswith("Request failed:"):
        # synthetic 500 = client-side transport failure; body names the cause
        handle_transport_error(str(e))   # proxy/DNS/TLS/timeout remediation
    else:
        raise

Prevention

When it happens

Trigger: No internet / blocked egress when litellm POSTs to `https://api.bfl.ai/v1/...`; wrong or unreachable custom base_url; connect/read timeout shorter than BFL's slow acknowledgement; corporate proxy not set (HTTP_PROXY/HTTPS_PROXY env vars missing); TLS interception with an untrusted CA.

Common situations: Air-gapped or proxy-locked CI environments; typo'd `api_base`/`base_url` config; sandboxed containers without CA certificates; flaky mobile/hotel networks. The underlying httpx error text is embedded in the message, so read the tail of the message to identify which transport failure it was.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/591d80228c3af319. Report an issue: GitHub.

Appendix: source

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

            input=prompt,
            api_key="",
            additional_args={
                "complete_input_dict": data,
                "api_base": complete_url,
                "headers": headers,
            },
        )

        # Make initial request
        try:
            response: Final = sync_client.post(
                url=complete_url,
                headers=headers,
                json=data,
                timeout=timeout,
            )
        except Exception as e:
            raise BlackForestLabsError(
                status_code=500,
                message=f"Request failed: {e}",
            )

        # Poll for result
        final_response: Final = self._poll_for_result_sync(
            initial_response=response,
            headers=headers,
            sync_client=sync_client,
        )

        # Transform response
        return self.config.transform_image_generation_response(
            model=model,
            raw_response=final_response,
            model_response=model_response,
            logging_obj=logging_obj,
            request_data=data,

View on GitHub (pinned to 77b7c6c40c)