Repository navigation
feat(codex): image models on the ChatGPT subscription channel - #532
Conversation
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
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
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_typereturns early for any fullimage/*type andconvert_to_base64passes aBase64payload through unvalidated.ImageFile::File { media_type: "image/png", data: Base64("not base64!!") }(or empty bytes) is POSTed as adata:URL; the siblingopenai/image/image_model.rs::image_file_to_bytesdecodes 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, sodata: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: Noneeven thoughresponse.completed.response.usageis present; the directgpt-image-2route 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 (timeoutunset) a stalled SSE makesdo_generatenever return; the direct route sets 600s. Wrap the stream drain in a timeout (response_timeoutis ignored for streaming handlers).
eric8810
left a comment
There was a problem hiding this comment.
认证/端点和模型映射正确,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.
|
For the review at #532 (review): Thanks for the review. All four points are fixed in 0d7a8d8.
|
|
For the review at #532 (review): Thanks for the review. All four blocking points are fixed in 0d7a8d8.
|
eric8810
left a comment
There was a problem hiding this comment.
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.
|
For the review at #532 (review): Thanks for the review. Fixed in b889064.
|
eric8810
left a comment
There was a problem hiding this comment.
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.
|
#542 已合入 master(8a5df14e),abi_primitives SIGSEGV 修了。sync 一次 master 后 CI 应该全绿,我直接合。 |
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.
|
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 |
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.
Closes #526
Summary
CodexProvider::imageandProvider::image_modelnow serve subscription image models inCodexMode::ChatGptAccount(codex.image). Previously every image id returnedNoSuchModel.gpt-image-2: JSON/images/generationswith{model,prompt}, and JSON/images/editswith one inlineimage_urlentry per input file.gpt-image-2.5-flare,gpt-image-2.5-sunburstand their-2026-09-08snapshots: streamed/responsesusinggpt-5.6-lunaand the forcedimage_generationtool. The request preserves the issue's instructions,store:false, tool model/action/optional size and PNG output format.response.output_item.doneitem that completed with a non-emptyresult, with fallback to the first completed image call in the final response. Success requiresresponse.completedwithstatus: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.response.completed.response.usage, like the direct route.TokenExpired; a 403 remains an API error.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 useHttpRequest::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 base64image/<subtype>returnInvalidArgumentwithout calling the endpoint, and thedata:scheme is matched case-insensitively. Media type parameters before;base64(for examplecharset) 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 reportsresponseId. ApiKey mode continues to returnNoSuchModelfor 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).data:URLs never reach the endpoint, that adata: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 usesgenerate_imagewhere 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, andRUSTDOCFLAGS='-D warnings' cargo +1.100.0 doc -p aimux-providers --no-deps --lockedpass.Checklist