Support OpenClaw image responses

This commit is contained in:
Mikei386
2026-09-15 17:58:37 +02:00
parent b48fcc63d3
commit eb799107e3
2 changed files with 20 additions and 1 deletions
+6 -1
View File
@@ -2355,6 +2355,7 @@ class Handler(BaseHTTPRequestHandler):
"invalid_request_error", "invalid_seed")
return
response_format_explicit = "response_format" in data
response_format = data.get("response_format", "url")
if response_format not in ("url", "b64_json"):
self._send_error(400, "'response_format' muss 'url' oder 'b64_json' sein",
@@ -2379,9 +2380,13 @@ class Handler(BaseHTTPRequestHandler):
for filename in results:
path = os.path.join(IMAGE_DIR, filename)
item: dict = {"url": f"{host}/images/{filename}", "b64_json": None}
if response_format == "b64_json":
# OpenClaw's OpenAI-compatible image parser requires b64_json but
# does not send response_format. Keep the URL for existing clients
# and add inline image data only when the format was omitted.
if response_format == "b64_json" or not response_format_explicit:
with open(path, "rb") as f:
item["b64_json"] = base64.b64encode(f.read()).decode()
if response_format == "b64_json":
item["url"] = None
items.append(item)
payload: dict = {"created": int(time.time()), "data": items}