{"record":{"id":"b516f1875396d0c0","repo":"xtekky/gpt4free","slug":"no-media-files-provided-for-image-generation","errorCode":null,"errorMessage":"No media files provided for image generation.","messagePattern":"No media files provided for image generation\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/hf_space/BlackForestLabs_Flux1Dev.py","lineNumber":124,"sourceCode":"            ]\n            conversation = JsonConversation(\n                zerogpu_token=api_key,\n                zerogpu_uuid=zerogpu_uuid,\n                session_hash=uuid.uuid4().hex,\n            )\n            if conversation.zerogpu_token is None:\n                (\n                    conversation.zerogpu_uuid,\n                    conversation.zerogpu_token,\n                ) = await get_zerogpu_token(cls.space, session, conversation, cookies)\n            async with cls.run(f\"post\", session, conversation, data) as response:\n                await raise_for_status(response)\n                assert (await response.json()).get(\"event_id\")\n                async with cls.run(\"get\", session, conversation) as event_response:\n                    await raise_for_status(event_response)\n                    async for chunk in event_response.iter_lines():\n                        if chunk.startswith(b\"data: \"):\n                            try:\n                                json_data = json.loads(chunk[6:])\n                                if json_data is None:\n                                    continue\n                                if json_data.get(\"msg\") == \"log\":\n                                    yield Reasoning(status=json_data[\"log\"])\n\n                                if json_data.get(\"msg\") == \"progress\":\n                                    if \"progress_data\" in json_data:\n                                        if json_data[\"progress_data\"]:\n                                            progress = json_data[\"progress_data\"][0]\n                                            yield Reasoning(\n                                                status=f\"{progress['desc']} {progress['index']}/{progress['length']}\"\n                                            )\n                                        else:\n                                            yield Reasoning(status=f\"Generating\")\n\n                                elif json_data.get(\"msg\") == \"process_generating\":\n                                    for item in json_data[\"output\"][\"data\"][0]:","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/hf_space/BlackForestLabs_Flux1Dev.py#L106-L142","documentation":"Note: the SOURCE block shown is Flux1Dev, but this message actually lives in BlackForestLabs_Flux1KontextDev.py:124. The Kontext (image-editing) model requires at least one input image: after merging the media argument with media found in messages, `if not media: raise ValueError(...)`. It is a pure caller-contract error — the Kontext Space edits images, so calling it text-only is invalid.","triggerScenarios":"Calling the flux-1-kontext provider with messages containing only text and no image attachments, and no media=[...] argument; passing media as an empty list; or passing images in a format that merge_media does not recognize (so they are dropped) — e.g. malformed message structures where the image part is not a standard image_url/content block.","commonSituations":"Using a generic chat client template against a Kontext image-to-image model without attaching an image; migrating code from the text-to-image Flux1Dev provider (which needs no image) to Kontext without adding image input; image URLs that fail merge_media's extraction heuristics.","solutions":["Attach at least one image: include an image_url content part in the messages, or pass media=[(image_bytes_or_path, name)] to the provider call.","Verify merge_media recognizes your message format — use standard OpenAI-style {'type':'image_url','image_url':{'url':...}} parts.","If you actually want text-to-image (no input image), use the BlackForestLabs_Flux1Dev provider instead of Kontext."],"exampleFix":"# before\nresponse = await BlackForestLabs_Flux1KontextDev.create_async_generator(\n    model=model, messages=[{\"role\":\"user\",\"content\":\"edit this\"}]\n)\n\n# after\nresponse = await BlackForestLabs_Flux1KontextDev.create_async_generator(\n    model=model,\n    messages=[{\"role\":\"user\",\"content\":[\n        {\"type\":\"text\",\"text\":\"add a hat\"},\n        {\"type\":\"image_url\",\"image_url\":{\"url\":\"data:image/png;base64,...\"}},\n    ]}],\n)","handlingStrategy":"validation","validationCode":"def has_media(messages, media=None) -> bool:\n    if media:\n        return True\n    for m in messages or []:\n        c = m.get('content')\n        if isinstance(c, list) and any(p.get('type') == 'image_url' for p in c):\n            return True\n    return False\n\nassert has_media(messages, media), 'Kontext requires at least one input image'","typeGuard":null,"tryCatchPattern":"try:\n    ...\nexcept ValueError as e:\n    if 'No media files' in str(e):\n        raise ValueError('Attach an input image for the Kontext image-editing model') from e","preventionTips":["Check for input media before calling Kontext-class image-editing models.","Use standard image_url message parts so merge_media recognizes them.","Reserve Flux1Dev for text-to-image and Kontext for image-to-image."],"tags":["hf-space","image-generation","validation","input-required"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}