Skip to content

fix(openai): suppress native image_generation tool for Codex models (#115)#183

Open
quangdang46 wants to merge 1 commit into
masterfrom
fix/openai-disable-image-gen-for-codex
Open

fix(openai): suppress native image_generation tool for Codex models (#115)#183
quangdang46 wants to merge 1 commit into
masterfrom
fix/openai-disable-image-gen-for-codex

Conversation

@quangdang46
Copy link
Copy Markdown
Owner

What

In ChatGPT mode, build_response_request unconditionally pushed { "type": "image_generation" } onto the request's tool array. The OpenAI Responses API rejects that tool for codex-family models (gpt-5.x-codex*, including the [1m] long-context suffix variants) with HTTP 400 ("unsupported tool image_generation for model …"), which aborted the entire session for ChatGPT-mode codex users.

This addresses issue #115: #115

Changes

  • src/provider/openai.rs: add Self::supports_native_image_generation(model_id) returning false for any model id whose lower-cased / [1m]-stripped form contains "codex". Gate the existing tools.push site by that helper. Non-codex ChatGPT models (gpt-5.x non-codex, gpt-4o, …) still receive the tool.
  • src/provider/openai_tests/payloads.rs: two regression tests:
    • test_chatgpt_payload_includes_native_image_generation_for_non_codex_models (gpt-5.5)
    • test_chatgpt_payload_excludes_native_image_generation_for_codex_models iterating gpt-5.3-codex, gpt-5.3-codex-spark, gpt-5.3-codex-spark[1m].

Tests

$ cargo test -p jcode --lib chatgpt_payload
test result: ok. 2 passed; 0 failed

Notes

Ports upstream PR 1jehuang#148.

In ChatGPT mode, build_response_request unconditionally pushed
{ "type": "image_generation" } onto the request's tool array. The
OpenAI Responses API rejects that tool for codex-family models
(gpt-5.x-codex*, including the [1m] long-context suffix variants)
with HTTP 400 ("unsupported tool image_generation for model …"),
which aborted the entire session for ChatGPT-mode codex users.

Add Self::supports_native_image_generation(model_id) returning false
for any model id whose lower-cased / [1m]-stripped form contains
"codex". Gate the tools.push site by that helper. Non-codex ChatGPT
models (gpt-5.x non-codex, gpt-4o, etc.) still receive the tool.

Two regression tests in src/provider/openai_tests/payloads.rs:
- test_chatgpt_payload_includes_native_image_generation_for_non_codex_models
- test_chatgpt_payload_excludes_native_image_generation_for_codex_models
  iterating gpt-5.3-codex, gpt-5.3-codex-spark, and gpt-5.3-codex-spark[1m].

Ports upstream PR 1jehuang#148.
Closes #115
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.

1 participant