Skip to content

ImageOutput.save() crashes on data: URLs returned by Gemini image models #587

@santoshkumarradha

Description

@santoshkumarradha

Summary

ImageOutput.save() in sdk/python/agentfield/multimodal_response.py ~line 99 calls requests.get(self.url) unconditionally on the URL branch, which raises InvalidSchema for data: URLs.

vision.generate_image_openrouter populates ImageOutput.url with whatever the OpenRouter response carries. For Gemini image models (e.g. google/gemini-2.5-flash-image), that value is a data:image/png;base64,... URL, not an HTTP URL.

Repro

from agentfield.multimodal_response import ImageOutput
img = ImageOutput(url="data:image/png;base64,iVBORw0KGgoAAAA...")
img.save("/tmp/out.png")

Error

requests.exceptions.InvalidSchema: No connection adapters were found for
'data:image/png;base64,iVBORw0KGgo...'

Suggested fix

In either:

  • generate_image_openrouter — when the response's url is a data: URL, base64-decode it once and populate b64_json instead, leaving url=None. Then the existing b64_json branch of save() handles it.
  • ImageOutput.save() / ImageOutput.get_bytes() — detect data: URLs and decode locally before falling through to requests.get.

Status

This is fixed on origin/mainget_bytes() now special-cases data: URLs and save() delegates to get_bytes(). The bug is still present in the latest released version agentfield==0.1.84, which is what surfaced this. Filing for visibility once an 0.1.85 release cuts so consumers can drop their workarounds.

Consumer workaround

reel-af ships a _save_image_output() helper plus a runtime monkey-patch (src/reel_af/sdk_patches.py::_patch_image_output_save) that sniffs data: URLs and decodes them itself before delegating back to the SDK for real HTTP URLs.

Found by the Python SDK consumer reel-af (an AgentField example pipeline).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:aiAI/LLM integrationbugSomething isn't workingsdk:pythonPython SDK related

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions