{"record":{"id":"40d35d856bc99cbc","repo":"BerriAI/litellm","slug":"error-parsing-initial-response-e-40d35d","errorCode":null,"errorMessage":"Error parsing initial response: {e}","messagePattern":"Error parsing initial response: (.+?)","errorType":"exception","errorClass":"BlackForestLabsError","httpStatus":null,"severity":"error","filePath":"litellm/llms/black_forest_labs/image_generation/handler.py","lineNumber":310,"sourceCode":"        max_wait: float = DEFAULT_MAX_POLLING_TIME,\n        interval: float = DEFAULT_POLLING_INTERVAL,\n        timeout: float | httpx.Timeout | None = None,\n    ) -> httpx.Response:\n        \"\"\"\n        Poll BFL API until result is ready (sync version).\n        \"\"\"\n        # Validate initial response status code\n        if initial_response.status_code >= 400:\n            raise BlackForestLabsError(\n                status_code=initial_response.status_code,\n                message=f\"BFL initial request failed: {initial_response.text}\",\n            )\n\n        # Parse initial response to get polling URL\n        try:\n            response_data: Final = initial_response.json()\n        except Exception as e:\n            raise BlackForestLabsError(\n                status_code=initial_response.status_code,\n                message=f\"Error parsing initial response: {e}\",\n            )\n\n        # Check for immediate errors\n        if \"errors\" in response_data:\n            raise BlackForestLabsError(\n                status_code=initial_response.status_code,\n                message=f\"BFL error: {response_data['errors']}\",\n            )\n\n        polling_url: Final = response_data.get(\"polling_url\")\n        if not polling_url:\n            raise BlackForestLabsError(\n                status_code=500,\n                message=\"No polling_url in BFL response\",\n            )\n","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/black_forest_labs/image_generation/handler.py#L292-L328","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Log the raw response body (response.text) on failure to identify what answered (HTML page, empty, error JSON).","Verify api_base in your config equals the genuine BFL base URL.","Bypass or correctly configure proxies for bfl.ai traffic.","Retry once; load-balancer misroutes are usually intermittent."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try:\n    img = litellm.image_generation(model=M, prompt=p)\nexcept Exception as e:\n    if \"Error parsing initial response\" in str(e):\n        log_body_and_probe_network()  # proxy/misroute diagnosis, then retry once\n        return litellm.image_generation(model=M, prompt=p)\n    raise","preventionTips":["Smoke-test the exact api_base with curl before wiring it into config.","Keep proxies off the bfl.ai path or make them transparent for JSON.","Log raw bodies on parse errors — they reveal which hop answered."],"tags":["bfl","json","response-parsing","proxy","image-generation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}