Skip to content

feat(image-gen): support Codex image inputs (salvage #55828) - #57017

Merged
kshitijk4poor merged 3 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/55828-codex-image-inputs
Jul 2, 2026
Merged

feat(image-gen): support Codex image inputs (salvage #55828)#57017
kshitijk4poor merged 3 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/55828-codex-image-inputs

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

The openai-codex (Codex OAuth) image-gen backend can now do image-to-image / reference-image editing — it previously hard-rejected any image_url/reference_image_urls and advertised text-only.

Salvage of @CrazyBoyM's #55828 onto current main, with one follow-up commit that reuses the shared magic-byte sniffer and gates it to the raster formats gpt-image-2 actually accepts.

Changes

  • plugins/image_gen/openai-codex/__init__.py:
    • Accept image_url + reference_image_urls; attach them as Responses input_image content parts alongside the prompt.
    • Normalize refs via the shared normalize_reference_images(...), clamp to 16 (same cap as the API-key OpenAI path).
    • Validate local/data-URL inputs by magic bytes (not extensions), 25MB cap, and route local paths through the agent.file_safety read guard before inlining.
    • Advertise modalities: ["text","image"] / max_reference_images: 16 only now that the path is wired.
    • Follow-up (ours): delegate magic-byte detection to the shared agent.image_routing._sniff_mime_from_bytes (drops a duplicated format table) and gate the result to png/jpeg/gif/webp — the raster set gpt-image-2's input_image accepts — so SVG/TIFF/ICO fail locally with a clear invalid_image_input error instead of an opaque server-side 400.
  • tests/plugins/image_gen/test_openai_codex_provider.py: payload shape with source+reference images, capability metadata, non-image + SVG rejection, 16-image clamp.
  • Docs: image-generation + tools-reference updated for Codex OAuth image editing.

Validation

Result
tests/plugins/image_gen/test_openai_codex_provider.py + dispatch 26 passed
Full tests/plugins/image_gen/ 172 passed
ruff (diff vs main) clean
E2E (real file I/O, temp HERMES_HOME) local PNG inlined + saved; .txt/nonexistent/fake-magic-byte/SVG/TIFF rejected invalid_image_input; refs clamp 20→16; text-to-image regression clean; .env/auth.json blocked by read guard (no credential exfil)

Fixes #21661.
Fixes #36737.

Closes #55828. Commits cherry-picked from @CrazyBoyM with authorship preserved.

CrazyBoyM and others added 3 commits July 2, 2026 17:03
… codex backend

Replace the plugin-local _IMAGE_MAGIC_MIME table + _sniff_image_mime
body with a delegation to agent.image_routing._sniff_mime_from_bytes,
the canonical magic-byte sniffer already used across the codebase, then
gate its result to the raster formats gpt-image-2's Responses
input_image actually accepts (png/jpeg/gif/webp).

The shared sniffer also recognizes SVG/TIFF/ICO; without the allowlist
those would pass local validation and be rejected server-side with an
opaque HTTP 400. Gating locally fails them cleanly as invalid_image_input.
Adds a regression test for SVG rejection.

Follow-up on top of @CrazyBoyM's NousResearch#55828.
@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) July 2, 2026 11:36
@kshitijk4poor
kshitijk4poor merged commit 0199505 into NousResearch:main Jul 2, 2026
29 checks passed
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins provider/openai OpenAI / Codex Responses API tool/vision Vision analysis and image generation labels Jul 2, 2026
@kshitijk4poor
kshitijk4poor deleted the salvage/55828-codex-image-inputs branch August 5, 2026 07:10
iainlane added a commit to iainlane/hermes-agent that referenced this pull request Aug 15, 2026
The Codex backend grew its own source-image handling when
image-to-image landed in NousResearch#57017, duplicating the read denylist and
magic-byte validation the sanctioned resolver already enforces. It
also carries two constraints the resolver can now express directly:
gpt-image-2's input_image caps at 25MB and accepts raster
PNG/JPEG/GIF/WEBP only, so a BMP or an oversized file has to fail
locally rather than as an opaque HTTP 400.

Replace _sniff_image_mime, _data_url_to_input_image_url and
_local_image_to_data_url with one resolve_source_to_url_sync() call
carrying the cap and the format allowlist. Public URLs pass through
for the API to fetch; local files and data: URIs are re-encoded under
the sniffed MIME, so a mislabelled header cannot reach the API
claiming a type gpt-image-2 will reject.

Neither constraint had test coverage before; both are now pinned at
the resolver and through the provider.
iainlane added a commit to iainlane/hermes-agent that referenced this pull request Aug 16, 2026
The Codex backend grew its own source-image handling when
image-to-image landed in NousResearch#57017, duplicating the read denylist and
magic-byte validation the sanctioned resolver already enforces. It
also carries two constraints the resolver can now express directly:
gpt-image-2's input_image caps at 25MB and accepts raster
PNG/JPEG/GIF/WEBP only, so a BMP or an oversized file has to fail
locally rather than as an opaque HTTP 400.

Replace _sniff_image_mime, _data_url_to_input_image_url and
_local_image_to_data_url with one resolve_source_to_url_sync() call
carrying the cap and the format allowlist. Public URLs pass through
for the API to fetch; local files and data: URIs are re-encoded under
the sniffed MIME, so a mislabelled header cannot reach the API
claiming a type gpt-image-2 will reject.

Neither constraint had test coverage before; both are now pinned at
the resolver and through the provider.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have provider/openai OpenAI / Codex Responses API tool/vision Vision analysis and image generation type/feature New feature or request

Projects

None yet

3 participants