{"record":{"id":"a55737b42b82e6ce","repo":"BerriAI/litellm","slug":"bfl-initial-request-failed-initial-response-text-a55737","errorCode":null,"errorMessage":"BFL initial request failed: {initial_response.text}","messagePattern":"BFL initial request failed: (.+?)","errorType":"exception","errorClass":"BlackForestLabsError","httpStatus":null,"severity":"error","filePath":"litellm/llms/black_forest_labs/image_generation/handler.py","lineNumber":301,"sourceCode":"            litellm_params=litellm_params_dict,\n            encoding=None,\n        )\n\n    def _poll_for_result_sync(\n        self,\n        initial_response: httpx.Response,\n        headers: dict,\n        sync_client: HTTPHandler,\n        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']}\",","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/black_forest_labs/image_generation/handler.py#L283-L319","documentation":"After the sync submission POST returns, its status code is checked before anything else. Any response >= 400 (BFL rejecting the create-job request: invalid key 401, quota 429, bad payload 400, server 5xx) is re-raised as BlackForestLabsError preserving the upstream status and body text. The body text carries BFL's own error details.","triggerScenarios":"litellm.image_generation on a black_forest_labs model where BFL answers the POST with 4xx/5xx — invalid or revoked API key (401), malformed/missing prompt or params (400), rate limit or exhausted credits (429), BFL internal errors (5xx).","commonSituations":"Expired BFL keys; hitting the free-tier credit ceiling; prompt validation failures; regional endpoint maintenance; sending parameters the endpoint does not accept.","solutions":["Read initial_response.text in the message — BFL states the exact reason (auth, quota, validation).","401/403: rotate/renew BFL_API_KEY.","429: back off, check your BFL billing/limits, reduce concurrency.","400: fix the flagged request field; 5xx: retry with backoff or wait for BFL status to clear."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"from litellm.exceptions import APIError\n\ntry:\n    img = litellm.image_generation(model=M, prompt=p)\nexcept APIError as e:\n    sc = getattr(e, \"status_code\", None)\n    if sc == 429:\n        backoff_and_retry()\n    elif sc in (401, 403):\n        alert_config(\"BFL key rejected\")\n    elif sc and sc >= 500:\n        retry_once()\n    else:\n        raise","preventionTips":["Branch on the preserved status_code instead of parsing message strings where possible.","Never retry 401/403 — fix credentials instead.","Track 429 rates per key and cap concurrency to stay under BFL limits."],"tags":["bfl","http-status","auth","rate-limit","image-generation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}