Skip to content

feat(codex): image models on the ChatGPT subscription channel - #532

Merged
eric8810 merged 10 commits into
masterfrom
feat/codex-image-models
Nov 24, 2026
Merged

eric8810 merged 10 commits into
masterfrom
feat/codex-image-models

Conversation

@zerob13

@zerob13 zerob13 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #526

Summary

CodexProvider::image and Provider::image_model now serve subscription image models in CodexMode::ChatGptAccount (codex.image). Previously every image id returned NoSuchModel.

  • gpt-image-2: JSON /images/generations with {model,prompt}, and JSON /images/edits with one inline image_url entry per input file.
  • gpt-image-2.5-flare, gpt-image-2.5-sunburst and their -2026-09-08 snapshots: streamed /responses using gpt-5.6-luna and the forced image_generation tool. The request preserves the issue's instructions, store:false, tool model/action/optional size and PNG output format.
  • The streamed result is taken from the first response.output_item.done item that completed with a non-empty result, with fallback to the first completed image call in the final response. Success requires response.completed with status:completed. Failure or incomplete events, malformed SSE JSON, missing image output, an item that never completed, and empty or malformed base64 payloads return errors. Failure diagnostics keep an allowlisted summary of the terminal event only, namely its type, provider code, response status and incomplete reason, so output items and their image payloads never reach the error, and a malformed frame is reported without its text.
  • The streamed route reports response.completed.response.usage, like the direct route.
  • Every API failure is non-retryable, including 5xx, resets and timeouts, so Core cannot repeat a potentially billed generation. A 401 maps to TokenExpired; a 403 remains an API error.
  • Direct requests carry a 600-second response_timeout. On the streamed route, streaming handlers are exempt from that timeout, so the SSE drain after the response headers arrive is bounded at 600 seconds instead; waiting for the response headers is not covered by that guard. Core's caller-provided timeout remains the outer bound. This PR is independent of fix(provider-utils): synchronous generations get a 10-minute exchange guard and are not replayed after send #531; after it lands, the local timeout policy can use HttpRequest::generation.

Validation and compatibility

Input images are decoded and validated before the request is built: invalid base64, empty data, and a data: URL that is not base64 image/<subtype> return InvalidArgument without calling the endpoint, and the data: scheme is matched case-insensitively. Media type parameters before ;base64 (for example charset) are accepted; the forwarded URL is rebuilt from the decoded bytes.

Calls require one output image and a prompt. Editing rejects masks and empty input lists. Provider options in the codex, openai, and configured provider namespaces are rejected, including quality/outputFormat. The direct model rejects size; 2.5 accepts dimensions satisfying the documented multiples-of-16, side, aspect-ratio and pixel-count constraints. Omitted size uses the server default. Aspect ratio and seed produce unsupported warnings.

Remote input images use the existing SSRF-guarded downloader without provider credentials and are then inlined. Image metadata follows the existing openai.images[] shape; 2.5 additionally reports responseId. ApiKey mode continues to return NoSuchModel for image models, as permitted by the issue. Multi-image editing follows the documented array shape but only single-image edits were confirmed by the source probe.

Verification

  • cargo +1.100.0 test -p aimux-providers --test codex_image_test --test codex_test: 40 passed (26 image tests and 14 existing Codex tests).
  • Added regressions establish that malformed SSE cannot be hidden by a later successful completion, that empty, whitespace and invalid base64 are rejected on both transports, that corrupt input images and invalid data: URLs never reach the endpoint, that a data: URL with media type parameters is accepted and normalized, that a stalled stream is bounded, that the streamed route reports usage, that an image call item is used only after it completed, and that failure diagnostics retain neither image payloads nor frame text. Each uses generate_image where a retry could replay the request and asserts exactly one request with the default retry policy.
  • cargo +1.100.0 fmt --all -- --check, cargo +1.100.0 clippy -p aimux-providers --all-targets --locked -- -D warnings, cargo +1.100.0 clippy -p aimux-providers --no-default-features --locked -- -D warnings, and RUSTDOCFLAGS='-D warnings' cargo +1.100.0 doc -p aimux-providers --no-deps --locked pass.
  • The initial implementation passed the full provider suite (5946 passed, 5 ignored); the follow-up validation fixes were checked with the focused suites above at head b889064.
  • No live account or billable API requests were made. The mock protocol fixtures come from the redacted probe described in the issue; a live entitlement/protocol check remains outstanding.

Checklist

  • Focused regression tests and existing Codex tests pass
  • Formatting and provider crate clippy pass
  • Updated subscription guide and changelog
  • Conventional commits
  • Local workspace-wide clippy and tests (not run in this follow-up; see CI)

@zerob13 zerob13 self-assigned this Nov 20, 2026
gpt-image-2 uses the direct JSON /images/generations and /images/edits
endpoints; gpt-image-2.5-flare, gpt-image-2.5-sunburst and their
-2026-09-08 snapshots use the streamed Responses image_generation tool.
Only probed fields are sent, 2.5 sizes are validated before sending,
every failure is non-retryable so a billed generation is not replayed,
and a 401 maps to TokenExpired. API-key mode still serves no image
models.

Closes #526
@zerob13
zerob13 marked this pull request as ready for review November 20, 2026 09:02

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 8b344c8. No P0/P1/P2; four P3 correctness/robustness issues.

  • P3 – invalid image input reaches the billed endpoint (aimux-providers/src/codex/image_model.rs:589-632): full_image_media_type returns early for any full image/* type and convert_to_base64 passes a Base64 payload through unvalidated. ImageFile::File { media_type: "image/png", data: Base64("not base64!!") } (or empty bytes) is POSTed as a data: URL; the sibling openai/image/image_model.rs::image_file_to_bytes decodes first. Since 5xx is non-retryable here, corrupt caller input becomes an opaque billed error.
  • P3 – data: input URLs bypass validation (:600): ImageFile::Url { url } if url.starts_with("data:") is forwarded verbatim, so data:text/plain;base64,... passes local validation; the prefix check is also case-sensitive (DATA:... falls into the download path). Validate the media type/base64 and compare case-insensitively.
  • P3 – 2.5 route drops usage (:413): usage: None even though response.completed.response.usage is present; the direct gpt-image-2 route reports it. Hosts lose billing telemetry for the more expensive path.
  • P3 – streamed 2.5 exchange has no bound (:331-338): with default call options (timeout unset) a stalled SSE makes do_generate never return; the direct route sets 600s. Wrap the stream drain in a timeout (response_timeout is ignored for streaming handlers).

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

认证/端点和模型映射正确,wiremock 覆盖也好,但还有几个阻塞:1) image_data_url 对任意 image/* Base64 不解码就直发,data: 前缀未做大小写检查,空/非法 Base64 会到计费端点;2) 2.5 SSE 完全没有 timeout,流挂死会永久等待且不可重试,请加 600s guard;3) 2.5 usage 被置 None,丢失计费遥测;4) retained image_generation_call 未检查 item status=completed。修好后再 approve。

Decode every inline input image and validate `data:` URLs before the request is built, so invalid base64, empty data, and a non-image or non-base64 `data:` URL fail with `InvalidArgument` instead of reaching the billed endpoint. The `data:` scheme is matched case-insensitively and the rebuilt URL is normalized.

Bound the streamed `gpt-image-2.5` drain with the same 600-second hang guard as the direct endpoints, since streaming handlers are exempt from the exchange timeout and a stalled SSE would otherwise never return.

Report `response.completed.response.usage` on the streamed route, and use an `image_generation_call` item only after it reached `completed` status.
A valid `data:` URL may carry media type parameters before the `;base64` marker, such as `data:image/png;charset=utf-8;base64,...`; the parser treated the whole parameter list as the marker and rejected these inputs instead of forwarding them like the previous implementation did. Accept any parameters and require only that the last one is `base64`, keeping the decoded, non-empty payload check. The error now names the missing `;base64` marker instead of claiming the payload is not base64. New tests cover parameterized inputs that are accepted and normalized, a marker that is not last, and the rejection message.
The 600-second guard on the streamed route covers the SSE drain after the response headers arrive; the wait for those headers is not bounded by it. Direct requests keep a 600-second response timeout over the whole exchange. Reword the subscription guide, changelog, and module comments so they claim only what the code guarantees.
Clippy rejects Iterator::last on a double-ended iterator; the parameter list is a Split, so take the trailing marker from the back without walking the whole iterator.
@yyhhyyyyyy

Copy link
Copy Markdown
Contributor

For the review at #532 (review):

Thanks for the review. All four points are fixed in 0d7a8d8.

  • Invalid image input no longer reaches the billed endpoint. image_data_url decodes every inline payload before the request is built, so invalid base64 and empty data fail with InvalidArgument locally, on both routes and for downloaded inputs too, matching how openai/image/image_model.rs::image_file_to_bytes decodes first. Tests: corrupt_input_images_are_rejected_before_sending (both models, and no request is sent) and input_data_urls_are_validated_before_sending.
  • data: input URLs are validated instead of forwarded. The media type must be a full image/<subtype>, the payload must decode as non-empty base64, and the scheme is matched case-insensitively, so an uppercase DATA: prefix is treated as inline data instead of falling into the download path. Media type parameters before ;base64, such as charset, are accepted. The forwarded URL is rebuilt from the decoded bytes, so what reaches the endpoint is always valid base64 with an image media type. Tests: input_data_urls_are_validated_before_sending, input_data_url_with_media_type_parameters_is_accepted, input_data_url_scheme_is_case_insensitive, and a parser unit test.
  • The 2.5 route reports usage again, read from response.completed.response.usage through the same extraction the direct route uses. Test: gpt_image_2_5_reports_usage_from_the_completed_response.
  • The streamed route now bounds the SSE drain at 600 seconds (STREAMED_EXCHANGE_TIMEOUT), because response_timeout does not apply to streaming handlers. This guard starts once the response headers arrive, so it does not cover the wait for those headers; the caller-provided ImageCallOptions.timeout remains the outer bound. A stalled stream now returns a non-retryable ApiCall with origin=local instead of waiting forever. Test: stalled_stream_is_bounded_and_not_replayed, which drains a never-ending stream under a short bound and asserts the error is not retryable.

@yyhhyyyyyy

Copy link
Copy Markdown
Contributor

For the review at #532 (review):

Thanks for the review. All four blocking points are fixed in 0d7a8d8.

  • Input images are decoded and validated before the request is built: invalid base64, empty data, a partial or non-image media type, and a data: URL that is not base64 image/<subtype> all return InvalidArgument without sending anything. Media type parameters before ;base64, such as charset, are accepted. The data: scheme is matched case-insensitively, so DATA: no longer falls into the download path. Tests: corrupt_input_images_are_rejected_before_sending, input_data_urls_are_validated_before_sending, input_data_url_with_media_type_parameters_is_accepted, input_data_url_scheme_is_case_insensitive.
  • The 2.5 SSE drain is bounded by its own 600 second guard (STREAMED_EXCHANGE_TIMEOUT): streaming handlers are exempt from response_timeout, and the guard starts after the response headers arrive, so a stalled stream fails with a non-retryable error instead of waiting forever. Test: stalled_stream_is_bounded_and_not_replayed.
  • The 2.5 route reports response.completed.response.usage again. Test: gpt_image_2_5_reports_usage_from_the_completed_response.
  • A retained image_generation_call item is used only when its status is completed; an item that never completed now returns InvalidResponseData instead of being treated as a result. Tests: gpt_image_2_5_ignores_an_item_that_did_not_complete and gpt_image_2_5_rejects_an_item_that_never_completed.

@yyhhyyyyyy
yyhhyyyyyy requested a review from eric8810 November 24, 2026 05:21

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Input validation, completed-event usage, the post-header drain timeout, and the completed-image check are addressed.

[P2] Do not retain image bytes in streamed failure diagnostics. stream_failure passes the whole terminal response to the common error helper. The helper redacts the request and data, but writes the same event verbatim into the public ApiCallError.response_body. An incomplete/failed terminal event can contain output items, so image payloads can still persist in the returned diagnostic. Pass an allowlisted, sanitized error summary (type, code, status and incomplete reason) as the response context; add a synthetic incomplete fixture with an image payload and assert it is absent from the structured error, including the raw body field. Preserve the no-replay behavior.

Static review of this head. Exact CI is green; no live generation calls.

A terminal stream event can carry image output items, so passing the whole event as the error context wrote the payload into ApiCallError.response_body. Report only the event type, provider code, response status and incomplete reason, and drop the frame text from image stream parse errors.
@yyhhyyyyyy

Copy link
Copy Markdown
Contributor

For the review at #532 (review):

Thanks for the review. Fixed in b889064.

  • stream_failure no longer passes the terminal event to the common error helper. The public response_body and the structured data now carry an allowlisted summary only: the event type, the provider code, the response status and the incomplete reason. Output items, image payloads included, cannot reach either field. gpt_image_2_5_failure_event_keeps_image_payload_out_of_the_error replays a synthetic response.incomplete event and a synthetic response.failed event that each carry an image payload, and asserts the payload is absent from both fields and from the message.
  • The same rule applied to the other path in this change that copied response bytes into a diagnostic: a malformed SSE frame used to repeat the whole frame text in its parse error. Image streams now report that the frame is not valid JSON without its contents. malformed_sse_frame_is_not_hidden_by_completed_or_replayed carries an image payload in the truncated frame and asserts it is absent from the error.
  • No replay is preserved: every failure remains non-retryable, and both tests assert exactly one request under the default retry policy.

@yyhhyyyyyy
yyhhyyyyyy requested a review from eric8810 November 24, 2026 06:11

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b889064 修复到位:stream_failure 现在只把 type/code/status/incomplete_reason 的 allowlist 摘要作为 response_body/data/event;额外把 JSON 解析失败路径里嵌入整帧文本的 message 也脱掉了。新测试带 canary 图片,旧实现下必挂、当前 26/26 通过,no-replay 保持。Approve。CI 的 Rust core 失败是 aimux-ffi abi_primitives 的 UAF race(#542 在修),C ABI 是 setup-java 下载损坏,都与本 PR 无关。

Master brought the ByteDance Ark media provider (#535), MiniMax H3 media (#534) and the openai-compatible asynchronous video gateway (#536). The only conflict was CHANGELOG.md, where both sides added one entry under Unreleased / Added; both entries are kept verbatim, master's video gateway entry first and the Codex image entry directly below it, which is the file's newest-first order. aimux-providers/src/lib.rs and openai/image/image_model.rs merged without conflict because the two sides changed disjoint lines.
@eric8810

Copy link
Copy Markdown
Contributor

CI 说明:当前 head 唯一红的 Rust core 是 aimux-ffi abi_primitives 的 SIGSEGV(#542 正在修的 UAF race,和本 PR 无关;重跑一次仍复现)。#542 合入后我重跑即可,不用在本 PR 处理。代码我已 approve。

@eric8810

Copy link
Copy Markdown
Contributor

#542 已合入 master(8a5df14e),abi_primitives SIGSEGV 修了。sync 一次 master 后 CI 应该全绿,我直接合。

@eric8810
eric8810 dismissed stale reviews from yyhhyyyyyy and themself November 24, 2026 10:25

All points in this review were addressed in later commits; current head re-reviewed and approved by eric8810. Dismissing my own stale review so only CI gates the merge.

Master brought the C ABI primitives race fix (#542) and the MiniMax media preset routing fix (#544). They touch only test code on this branch: aimux-ffi/tests/abi_primitives.rs, aimux-providers/tests/minimax_media_test.rs and scripts/tests/test_check_native_artifact.py. There were no conflicts.
@yyhhyyyyyy

Copy link
Copy Markdown
Contributor

Re the note on the failing check: merged master (8a5df14) into the branch with a merge commit rather than a rebase, so the new head is 2230296. The full local gate set passes on the merged tree, including the aimux-ffi abi_primitives test from #542 and the aimux-providers minimax_media_test from #544.

@eric8810
eric8810 merged commit 0402682 into master Nov 24, 2026
14 checks passed
cunninghamcard-bit pushed a commit to cunninghamcard-bit/aimux that referenced this pull request Nov 25, 2026
PRs arcships#509 and arcships#510 were stacked on arcships#508's branch and merged there, so
their merge commits (aec27d4, a2f0002) never reached master. This
brings the feat/provider-descriptors-and-config tip (a2f0002) back
onto master and reconciles it with the arcships#538 ops refactor.

Conflicts resolved:
- aimux-ops/src/ops/provider.rs, registry.rs: re-applied the arcships#509/arcships#510
  semantics (LanguageApi sub-method dispatch, package descriptors,
  provider.descriptors / registry.fromConfig|list|update, env allowlist,
  StringOrEnv settings, separator, atomic update) on top of the arcships#538
  Params<'_>/CallFuture<'_> / HandleField types.
- codex/provider.rs, openai_compatible/provider.rs: kept both the
  arcships#532/arcships#536 image/video model hooks and the new language_model_with_api.
- CHANGELOG.md: kept both entries.

Verified: cargo check --workspace --all-targets; aimux-ops 289 tests,
aimux-core 590, aimux-provider-utils 263, aimux-ffi 24, aimux-providers
4654 (2 local-proxy env failures reproduce on master); codegen --check,
fmt, layout, boundaries, sync_registry, gen_providers_doc all clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] Codex 订阅通道支持图片模型(gpt-image-2 与 gpt-image-2.5 系列)

4 participants