xtekky/gpt4free · error · ValueError

No media files provided for image generation.

Error message

No media files provided for image generation.

What it means

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.

Source

Thrown at g4f/Provider/hf_space/BlackForestLabs_Flux1Dev.py:124

            ]
            conversation = JsonConversation(
                zerogpu_token=api_key,
                zerogpu_uuid=zerogpu_uuid,
                session_hash=uuid.uuid4().hex,
            )
            if conversation.zerogpu_token is None:
                (
                    conversation.zerogpu_uuid,
                    conversation.zerogpu_token,
                ) = await get_zerogpu_token(cls.space, session, conversation, cookies)
            async with cls.run(f"post", session, conversation, data) as response:
                await raise_for_status(response)
                assert (await response.json()).get("event_id")
                async with cls.run("get", session, conversation) as event_response:
                    await raise_for_status(event_response)
                    async for chunk in event_response.iter_lines():
                        if chunk.startswith(b"data: "):
                            try:
                                json_data = json.loads(chunk[6:])
                                if json_data is None:
                                    continue
                                if json_data.get("msg") == "log":
                                    yield Reasoning(status=json_data["log"])

                                if json_data.get("msg") == "progress":
                                    if "progress_data" in json_data:
                                        if json_data["progress_data"]:
                                            progress = json_data["progress_data"][0]
                                            yield Reasoning(
                                                status=f"{progress['desc']} {progress['index']}/{progress['length']}"
                                            )
                                        else:
                                            yield Reasoning(status=f"Generating")

                                elif json_data.get("msg") == "process_generating":
                                    for item in json_data["output"]["data"][0]:

View on GitHub (pinned to 973504e177)

Solutions

  1. 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.
  2. Verify merge_media recognizes your message format — use standard OpenAI-style {'type':'image_url','image_url':{'url':...}} parts.
  3. If you actually want text-to-image (no input image), use the BlackForestLabs_Flux1Dev provider instead of Kontext.

Example fix

# before
response = await BlackForestLabs_Flux1KontextDev.create_async_generator(
    model=model, messages=[{"role":"user","content":"edit this"}]
)

# after
response = await BlackForestLabs_Flux1KontextDev.create_async_generator(
    model=model,
    messages=[{"role":"user","content":[
        {"type":"text","text":"add a hat"},
        {"type":"image_url","image_url":{"url":"data:image/png;base64,..."}},
    ]}],
)
Defensive patterns

Strategy: validation

Validate before calling

def has_media(messages, media=None) -> bool:
    if media:
        return True
    for m in messages or []:
        c = m.get('content')
        if isinstance(c, list) and any(p.get('type') == 'image_url' for p in c):
            return True
    return False

assert has_media(messages, media), 'Kontext requires at least one input image'

Try / catch

try:
    ...
except ValueError as e:
    if 'No media files' in str(e):
        raise ValueError('Attach an input image for the Kontext image-editing model') from e

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/b516f1875396d0c0. Report an issue: GitHub.