{"record":{"id":"66ae86c65e3e060f","repo":"xtekky/gpt4free","slug":"unexpected-response-result","errorCode":null,"errorMessage":"Unexpected response: {result}","messagePattern":"Unexpected response: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/hf/HuggingFaceMedia.py","lineNumber":288,"sourceCode":"                                )\n                            elif task == \"text-to-image\":\n                                try:\n                                    return provider_info, ImageResponse(\n                                        [\n                                            item[\"url\"]\n                                            if isinstance(item, dict)\n                                            else item\n                                            for item in result.get(\n                                                \"images\",\n                                                result.get(\n                                                    \"data\", result.get(\"output\")\n                                                ),\n                                            )\n                                        ],\n                                        prompt,\n                                    )\n                                except Exception:\n                                    raise ValueError(f\"Unexpected response: {result}\")\n                            elif (\n                                task == \"text-to-video\"\n                                and result.get(\"output\") is not None\n                            ):\n                                return provider_info, VideoResponse(\n                                    result[\"output\"], prompt\n                                )\n                            raise ValueError(f\"Unexpected response: {result}\")\n                        async for chunk in save_response_media(\n                            response, prompt, [aspect_ratio, model]\n                        ):\n                            return provider_info, chunk\n\n            await raise_for_status(last_response)\n\n        background_tasks = set()\n        running_tasks = set()\n        started = time.time()","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/hf/HuggingFaceMedia.py#L270-L306","documentation":"Raised by HuggingFaceMedia when the JSON response for a media task could not be converted into an ImageResponse — the except Exception around image extraction (from result['images'] / ['data'] / ['output']) fired. ValueError with the full result payload, meaning the router returned JSON in an unexpected shape for an image task.","triggerScenarios":"text-to-image (or similar) task returns JSON where the images/data/output fields are missing, null, or malformed so the list comprehension inside ImageResponse construction throws.","commonSituations":"A provider returns a nested error object or an empty generation with 200 status; provider API schema changes; non-image JSON (e.g. a text blob) routed to an image task.","solutions":["Inspect the result payload in the message — it shows exactly which shape came back","Retry — some providers intermittently return empty bodies with success status","Pin a different provider via 'model:provider_key' to avoid the misbehaving one","Update g4f / report the provider's new response schema"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    provider_info, media = await generate(extra_body)\nexcept ValueError as e:\n    if 'Unexpected response' in str(e):\n        provider_info, media = await generate(extra_body)  # empty shape is often transient\n    else:\n        raise","preventionTips":["Retry once on malformed image payloads before failing over","Pin providers with known-stable response shapes via 'model:provider'","Log the embedded result payload to identify which provider misbehaved"],"tags":["huggingface","image-generation","unexpected-response","parsing"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}