Skip to content

The agent that grows with you

fix(codex): unsupported inline image formats no longer 400 the whole Responses request

teknium12f3395204439
diff --git a/agent/codex_responses_adapter.py b/agent/codex_responses_adapter.py
index a23d2a8ed1b..46c9cf6336e 100644
--- a/agent/codex_responses_adapter.py
+++ b/agent/codex_responses_adapter.py
@@ -93,6 +93,10 @@ _IMAGE_PART_TYPES = {"image_url", "input_image"}
_VIDEO_PART_TYPES = {"video", "video_url", "input_video"}
_OUTPUT_TEXT_TYPES = {"output_text", "text"}
_ASSISTANT_IMAGE_PLACEHOLDER = "[Assistant image omitted during replay]"
+# Inline data-URL subtypes the Responses backends accept as ``input_image``. Anything else
+# (SVG source, BMP, TIFF, ...) 400s the WHOLE request — and, once baked into history, every
+# later turn too — so it is downgraded to a text placeholder at this converging seam (#29711).
+_RESPONSES_INLINE_IMAGE_SUBTYPES = frozenset({"jpeg", "png", "gif", "webp"})
_INCOMPLETE_STATUSES = {"queued", "in_progress", "incomplete"}
_RESPONSE_MESSAGE_STATUSES = {"completed", "incomplete", "in_progress"}
@@ -209,10 +213,21 @@ def _iter_content_parts(content: list) -> Iterator[tuple[str, Any]]:
yield "image", part
+def _unsupported_inline_image_subtype(url: str) -> Optional[str]:
+ """``image/<subtype>`` of a ``data:image/...`` URL the Responses backends reject; None for
+ accepted rasters and for non-data URLs (the provider owns remote-URL validation)."""
+ header = url.partition(",")[0].lower()
+ if not header.startswith("data:image/"):
+ return None
+ subtype = header[len("data:image/"):].split(";", 1)[0].strip()
+ return None if subtype in _RESPONSES_INLINE_IMAGE_SUBTYPES else f"image/{subtype or 'unknown'}"
+
+
def _input_image_part(part: Dict[str, Any], role: str = "user", *, keep_empty_url: bool) -> Optional[Dict[str, Any]]:
"""Responses image part from a chat/Responses image part (``image_url`` may be a str or
``{url, detail}``). Assistant → text placeholder (an assistant ``input_image`` 400s every
- replay); user → ``input_image``, None for an empty url unless ``keep_empty_url``."""
+ replay); user → ``input_image``, None for an empty url unless ``keep_empty_url``; an inline
+ image of an unsupported subtype (e.g. ``image/svg+xml``) → text placeholder."""
if role == "assistant":
return {"type": "output_text", "text": _ASSISTANT_IMAGE_PLACEHOLDER}
url, detail = part.get("image_url"), part.get("detail")
@@ -220,7 +235,10 @@ def _input_image_part(part: Dict[str, Any], role: str = "user", *, keep_empty_ur
url, detail = url.get("url"), url.get("detail", detail)
if not _nonempty_str(url) and not keep_empty_url:
return None
- image_part: Dict[str, Any] = {"type": "input_image", "image_url": str(url or "")}
+ url = str(url or "")
+ if (mime := _unsupported_inline_image_subtype(url)) is not None:
+ return {"type": "input_text", "text": f"[image omitted: {mime} is not a supported image format]"}
+ image_part: Dict[str, Any] = {"type": "input_image", "image_url": url}
if _nonblank(detail):
image_part["detail"] = detail.strip()
return image_part
diff --git a/tests/agent/test_codex_responses_adapter.py b/tests/agent/test_codex_responses_adapter.py
index 1f773efc353..1bec7ce3f7b 100644
--- a/tests/agent/test_codex_responses_adapter.py
+++ b/tests/agent/test_codex_responses_adapter.py
@@ -93,6 +93,50 @@ def test_chat_content_keeps_images_on_user_role():
}]
+_SVG_DATA_URL = "data:image/svg+xml;base64,PHN2Zy8+"
+_PNG_DATA_URL = "data:image/png;base64,iVBORw0KGgo="
+
+
+def test_unsupported_inline_image_downgrades_to_text_in_message_and_tool_output():
+ """#29711: a data:image/svg+xml part 400s the whole Codex request ('does not represent a valid
+ image') on every replay. Both carriers — user message content and the persisted vision_analyze
+ function_call_output — must send a text placeholder while the valid PNG still goes as input_image."""
+ messages = [
+ {"role": "user", "content": [
+ {"type": "image_url", "image_url": {"url": _PNG_DATA_URL, "detail": "high"}},
+ {"type": "image_url", "image_url": {"url": _SVG_DATA_URL}},
+ ]},
+ {"role": "assistant", "content": None, "tool_calls": [
+ {"id": "call_v1", "type": "function", "function": {"name": "vision_analyze", "arguments": "{}"}}]},
+ {"role": "tool", "tool_call_id": "call_v1", "content": [
+ {"type": "text", "text": "rendered"}, {"type": "image_url", "image_url": {"url": _SVG_DATA_URL}}]},
+ ]
+ items = _chat_messages_to_responses_input(messages)
+ user, tool_output = items[0], items[-1]
+ assert user["content"] == [
+ {"type": "input_image", "image_url": _PNG_DATA_URL, "detail": "high"},
+ {"type": "input_text", "text": "[image omitted: image/svg+xml is not a supported image format]"},
+ ]
+ assert tool_output["type"] == "function_call_output"
+ assert [p["type"] for p in tool_output["output"]] == ["input_text", "input_text"]
+ assert "image/svg+xml" in tool_output["output"][1]["text"]
+
+
+def test_preflight_downgrades_unsupported_inline_image_but_keeps_remote_urls():
+ """The preflight validator is the last seam before the wire: an svg data URL in already
+ Responses-shaped input becomes text; https URLs are the provider's to validate and pass through."""
+ items = _preflight_codex_input_items([
+ {"role": "user", "content": [
+ {"type": "input_image", "image_url": _SVG_DATA_URL},
+ {"type": "input_image", "image_url": "https://example.invalid/p.svg"},
+ ]},
+ {"type": "function_call_output", "call_id": "call_1", "output": [{"type": "input_image", "image_url": _SVG_DATA_URL}]},
+ ])
+ assert [p["type"] for p in items[0]["content"]] == ["input_text", "input_image"]
+ assert items[0]["content"][1]["image_url"] == "https://example.invalid/p.svg"
+ assert items[1]["output"] == [{"type": "input_text", "text": "[image omitted: image/svg+xml is not a supported image format]"}]
+
+
@pytest.mark.parametrize("part_type", ["video_url", "video", "input_video"])
def test_chat_content_rejects_video_instead_of_sending_text_only(part_type):
content = [
diff --git a/website/docs/user-guide/features/vision.md b/website/docs/user-guide/features/vision.md
index ac920f410aa..744fce67055 100644
--- a/website/docs/user-guide/features/vision.md
+++ b/website/docs/user-guide/features/vision.md
@@ -205,6 +205,16 @@ When a user attaches an image — from the CLI clipboard, the gateway (Telegram/
You don't configure this — Hermes looks up your current model's capability in the provider metadata and picks the right path automatically. The practical effect: you can switch between vision and non-vision models mid-session and image handling "just works" without changing your workflow. Text-only models get coherent context about the image rather than a broken multimodal payload they'd have to reject.
+To override the automatic choice, set `agent.image_input_mode` in `config.yaml`:
+
+| Value | Behavior |
+|-------|----------|
+| `auto` (default) | Native pixels when the model reports vision support, `vision_analyze` description otherwise. Configuring an explicit `auxiliary.vision` backend (a `provider` other than `auto`, or a `model` / `base_url`) also selects the description path, even for a vision-capable main model. |
+| `native` | Always attach pixels, even when the catalog says the model is text-only. |
+| `text` | Always route images through the `vision_analyze` describer, never attach pixels to the main request. |
+
+This is the knob to reach for when a backend accepts text but rejects native image input (for example an `openai-codex` account whose backend answers image requests with `server_error`): keep your main model and point `auxiliary.vision` at a different vision-capable provider and model (with `auxiliary.vision.provider: auto` the describer would auto-detect the same main model again). That alone switches images to the description path in `auto` mode; `agent.image_input_mode: text` makes the same choice explicit.
+
Which auxiliary model handles the text-description path is configurable under `auxiliary.vision` — see [Auxiliary Models](../configuration.md#auxiliary-models).
### `vision_analyze` has the same dual behavior