{"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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/black_forest_labs/image_generation/handler.py#L292-L328","documentation":"Sync BFL flow: the initial POST returned HTTP < 400, but `initial_response.json()` threw, so the handler wraps the parse exception as BlackForestLabsError with the upstream status code. A success-status response with a non-JSON body is unusual - typically an intermediary (proxy, ingress, captive portal) replaced the body, or the connection truncated mid-body.","triggerScenarios":"Corporate proxy or API gateway returning its own 200/3xx HTML page instead of passing BFL's JSON through; captive-portal/WiFi login page intercepting the request; truncated response body from a flaky link causing httpx JSONDecodeError.","commonSituations":"Enterprise networks with TLS inspection; hotel/airport WiFi before authentication; misconfigured service mesh sidecar responding before upstream; rare truncation on unstable connections. If it reproduces 100% of the time, an interceptor is almost certainly involved.","solutions":["Log the raw body (litellm verbose logging or a custom success handler) to identify who generated the non-JSON response.","Bypass or correctly configure the proxy/sidecar for api.bfl.ai.","Retry once - truncation cases are transient.","Verify the same request with curl from the identical network path; if curl also returns HTML, the problem is outside LiteLLM."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from litellm.llms.black_forest_labs.common_utils import BlackForestLabsError\n\ntry:\n    resp = litellm.image_generation(model=\"flux-pro-1.1\", prompt=p)\nexcept BlackForestLabsError as e:\n    if \"Error parsing initial response\" in str(e):\n        log.error(\"non-JSON submit response (proxy interference?) status=%s\", e.status_code)\n        resp = retry_once(lambda: litellm.image_generation(model=\"flux-pro-1.1\", prompt=p))\n    else:\n        raise","preventionTips":["Keep the submit path proxy-clean or explicitly whitelist api.bfl.ai.","Treat a 2xx-with-non-JSON body as an interception signal, not an upstream bug.","Retain raw bodies in debug logs for a fast diagnosis."],"tags":["litellm","black-forest-labs","flux","json","response-parsing","proxy","sync"],"backgroundTag":"invalid-json-response","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}