hermes - ✅(Solved) Fix bug(image-gen): openai-codex gpt-image-2 fails with tool_choice 400, then empty_response without image_generation_call [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#19505Fetched 2026-05-05 06:06:23
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×3cross-referenced ×1

openai-codex image generation against gpt-image-2-medium currently fails in two stages against the Codex backend:

  1. Bundled/original plugin request shape fails with:

    • 400 invalid_request_error
    • Tool choice 'image_generation' not found in 'tools' parameter.
  2. After removing the tool_choice block from plugins/image_gen/openai-codex/__init__.py, the request no longer 400s, but the backend still never emits any image-generation events/items. Hermes then fails with:

    • Codex response contained no image_generation_call result
    • error_type: empty_response

This appears to be a compatibility gap between the current openai-codex image-gen plugin request shape and the live Codex backend behavior, rather than a local config/cache issue.

Error Message

"error": "OpenAI image generation via Codex auth failed: Error code: 400 - {'error': {'message': "Tool choice 'image_generation' not found in 'tools' parameter.", 'type': 'invalid_request_error', 'param': 'tool_choice', 'code': None}}", "error": "Codex response contained no image_generation_call result",

Root Cause

The same request no longer 400s, but Hermes still fails because no image tool call/result ever arrives.

Fix Action

Fix / Workaround

Reproduction (minimal patch: remove tool_choice)

  • Original bundled request shape: fails at request validation (tool_choice 400)
  • Minimal patched request shape: request completes, but the backend never invokes/returns image generation output

PR fix notes

PR #19979: fix(image_gen): drop unsupported tool_choice from openai-codex request

Description (problem / solution / changelog)

What does this PR do?

Addresses the stage-1 400 documented in #19505: the Codex backend rejects every tool_choice shape for the hosted image_generation tool with 400 invalid_request_error: Tool choice 'image_generation' not found in 'tools' parameter. The backend resolves tool_choice as a function-tool name and never recognizes hosted-tool entries like image_generation.

The bundled plugin sent tool_choice={"type": "allowed_tools", "mode": "required", "tools": [{"type": "image_generation"}]} alongside tools=[{"type": "image_generation", ...}]. Removing the tool_choice block is the only request shape Codex currently accepts; the existing instructions already nudge the host model toward the tool, so steering doesn't regress.

Stage-2 not addressed here. The reporter notes that even after the 400 is gone, the host model gpt-5.4 still doesn't always invoke the tool (no image_generation_call events emitted, Hermes then fails with error_type: empty_response). That appears to need backend-side investigation of whether Codex actually honors hosted image_generation from the chat surface; the reporter has already exhausted obvious request-shape variants (auto, omission, partial_images=0). I left Fixes off the issue ref deliberately so the issue stays open for the empty-response work.

Related Issue

Addresses #19505 (stage-1 only)

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • plugins/image_gen/openai-codex/__init__.py — remove the broken tool_choice block from the client.responses.stream(...) call; add a short comment explaining why (hosted-tool name rejected as function-tool name by the Codex backend).
  • tests/plugins/image_gen/test_openai_codex_provider.py — flip the test_codex_stream_request_shape assertion to lock in "tool_choice" not in captured. Verified the test fails without the source change (stash → run → restore round-trip).

How to Test

  1. Run pytest tests/plugins/image_gen/ -q → 61 passed.
  2. Reproduction (requires a Codex OAuth credential; see issue for full env):
    • On main: hermes -q "generate an image of a cat" with image_gen.provider: openai-codex → HTTP 400 Tool choice 'image_generation' not found in 'tools' parameter.
    • On this branch: same command → request succeeds; if gpt-5.4 then chooses to invoke image_generation, image is returned. (Empty-response stage-2 path remains; see #19505 for ongoing diagnosis.)

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix
  • I've run pytest tests/plugins/image_gen/ -q and all tests pass
  • I've added tests for my changes
  • I've tested on my platform: macOS darwin-arm64

Documentation & Housekeeping

  • I've updated relevant documentation — N/A (single-line comment in source explains the workaround)
  • I've updated cli-config.yaml.example if I added/changed config keys — N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — N/A
  • I've considered cross-platform impact (Windows, macOS) — N/A (request-shape change only)
  • I've updated tool descriptions/schemas if I changed tool behavior — N/A

Changed files

  • plugins/image_gen/openai-codex/__init__.py (modified, +9/-5)
  • tests/plugins/image_gen/test_openai_codex_provider.py (modified, +4/-3)

Code Example

with client.responses.stream(
    model=_CODEX_CHAT_MODEL,
    store=False,
    instructions=_CODEX_INSTRUCTIONS,
    input=[{
        "type": "message",
        "role": "user",
        "content": [{"type": "input_text", "text": prompt}],
    }],
    tools=[{
        "type": "image_generation",
        "model": API_MODEL,
        "size": size,
        "quality": quality,
        "output_format": "png",
        "background": "opaque",
        "partial_images": 1,
    }],
    tool_choice={
        "type": "allowed_tools",
        "mode": "required",
        "tools": [{"type": "image_generation"}],
    },
)

---

{
  "success": false,
  "error_type": "api_error",
  "error": "OpenAI image generation via Codex auth failed: Error code: 400 - {'error': {'message': \"Tool choice 'image_generation' not found in 'tools' parameter.\", 'type': 'invalid_request_error', 'param': 'tool_choice', 'code': None}}",
  "provider": "openai-codex",
  "model": "gpt-image-2-medium"
}

---

tool_choice={
    "type": "allowed_tools",
    "mode": "required",
    "tools": [{"type": "image_generation"}],
},

---

{
  "success": false,
  "error_type": "empty_response",
  "error": "Codex response contained no image_generation_call result",
  "provider": "openai-codex",
  "model": "gpt-image-2-medium"
}

---

{
  "status": "completed",
  "output_text": "",
  "output_count": 0,
  "output": []
}
RAW_BUFFERClick to expand / collapse

Summary

openai-codex image generation against gpt-image-2-medium currently fails in two stages against the Codex backend:

  1. Bundled/original plugin request shape fails with:

    • 400 invalid_request_error
    • Tool choice 'image_generation' not found in 'tools' parameter.
  2. After removing the tool_choice block from plugins/image_gen/openai-codex/__init__.py, the request no longer 400s, but the backend still never emits any image-generation events/items. Hermes then fails with:

    • Codex response contained no image_generation_call result
    • error_type: empty_response

This appears to be a compatibility gap between the current openai-codex image-gen plugin request shape and the live Codex backend behavior, rather than a local config/cache issue.

Environment

  • Repo: NousResearch/hermes-agent
  • Checkout tested: 167b5648ea609aafa85f56c5714f7abda5091ed6
  • git describe: v2026.4.30-227-g167b5648e-dirty
  • Runtime: editable checkout under ~/.hermes/hermes-agent
  • Profile: bot2
  • Provider: openai-codex
  • Image model/tier returned by Hermes: gpt-image-2-medium
  • Base URL: https://chatgpt.com/backend-api/codex
  • Auth type: Codex OAuth credential in profile auth.json
  • image_gen.provider: openai-codex
  • image_gen.use_gateway: false
  • credential_pool_strategies.openai-codex: fill_first
  • Credential pool simplified to a single usable openai-codex OAuth entry

What was ruled out

We explicitly ruled out the most likely local-environment causes:

  • Gateway restart/cache issue
    • Reproduced before and after gateway restart
  • Dirty working tree affecting behavior
    • Reproduced from a clean detached worktree at the same commit
  • Credential-pool rotation confusion
    • Pool reduced to a single openai-codex OAuth credential
  • Missing auth
    • Runtime selects a valid Codex OAuth token and reaches the backend
  • Config mismatch around provider selection
    • Reproduced with direct plugin invocation, outside Telegram/gateway flow

Reproduction (original bundled plugin)

The bundled plugin currently sends a request shaped like this in plugins/image_gen/openai-codex/__init__.py:

with client.responses.stream(
    model=_CODEX_CHAT_MODEL,
    store=False,
    instructions=_CODEX_INSTRUCTIONS,
    input=[{
        "type": "message",
        "role": "user",
        "content": [{"type": "input_text", "text": prompt}],
    }],
    tools=[{
        "type": "image_generation",
        "model": API_MODEL,
        "size": size,
        "quality": quality,
        "output_format": "png",
        "background": "opaque",
        "partial_images": 1,
    }],
    tool_choice={
        "type": "allowed_tools",
        "mode": "required",
        "tools": [{"type": "image_generation"}],
    },
)

Actual result

{
  "success": false,
  "error_type": "api_error",
  "error": "OpenAI image generation via Codex auth failed: Error code: 400 - {'error': {'message': \"Tool choice 'image_generation' not found in 'tools' parameter.\", 'type': 'invalid_request_error', 'param': 'tool_choice', 'code': None}}",
  "provider": "openai-codex",
  "model": "gpt-image-2-medium"
}

Reproduction (minimal patch: remove tool_choice)

After removing only this block:

tool_choice={
    "type": "allowed_tools",
    "mode": "required",
    "tools": [{"type": "image_generation"}],
},

The same request no longer 400s, but Hermes still fails because no image tool call/result ever arrives.

Actual result

{
  "success": false,
  "error_type": "empty_response",
  "error": "Codex response contained no image_generation_call result",
  "provider": "openai-codex",
  "model": "gpt-image-2-medium"
}

Stream/event inspection

With tool_choice removed, direct stream inspection shows the backend completing the request without any image_generation events at all.

Observed event pattern:

  • response.created
  • response.in_progress
  • response.output_item.added (message)
  • response.content_part.added
  • response.output_text.delta / response.output_text.done (sometimes empty)
  • response.output_item.done (message)
  • a second message output item
  • response.completed

Not observed:

  • response.image_generation_call.partial_image
  • response.output_item.done with item.type == "image_generation_call"
  • any final response.output items

Final response summary observed:

{
  "status": "completed",
  "output_text": "",
  "output_count": 0,
  "output": []
}

Additional variants tested

  • tool_choice='auto'
    • No 400, but still no image-generation events/items
  • partial_images=0
    • No 400, but still no image-generation events/items
  • Omitting instructions
    • Backend returns 400 with Instructions are required

Expected behavior

One of the following should work reliably for the openai-codex image-gen plugin:

  1. The bundled/original request shape should be accepted by the live Codex backend and return an image_generation_call item/result, or
  2. The plugin should be updated to the currently supported request shape for Codex image generation so that Hermes can actually receive image events/results.

Actual behavior

  • Original bundled request shape: fails at request validation (tool_choice 400)
  • Minimal patched request shape: request completes, but the backend never invokes/returns image generation output

Relevant files

  • plugins/image_gen/openai-codex/__init__.py
  • tests/plugins/image_gen/test_openai_codex_provider.py
  • potentially any Codex Responses compatibility layer assumptions around tool invocation

Suggested maintainer follow-up

  • Verify the currently supported Codex Responses request shape for image generation against https://chatgpt.com/backend-api/codex
  • Re-check whether tool_choice is still supported in this path
  • If tool_choice is unsupported, update provider tests so they match the live backend contract
  • If the backend now requires a different image tool invocation shape, update the plugin accordingly

Notes

A likely related but not identical issue is #5736 (openai-codex empty response.output on gpt-5.x agent-loop requests). This report is specifically about the bundled openai-codex image generation plugin path.

extent analysis

TL;DR

The openai-codex image generation plugin fails due to a compatibility gap with the live Codex backend, and removing the tool_choice block does not resolve the issue.

Guidance

  • Verify the currently supported Codex Responses request shape for image generation against the Codex backend API.
  • Check if the tool_choice parameter is still supported in the current backend contract.
  • Update the openai-codex image generation plugin to match the live backend contract, potentially removing or modifying the tool_choice block.
  • Review and update provider tests to ensure they match the live backend contract.

Example

No code example is provided as the issue requires verification of the backend contract and potential updates to the plugin code.

Notes

The issue is specific to the openai-codex image generation plugin and may be related to changes in the Codex backend API. Resolving the issue requires verifying the current backend contract and updating the plugin code accordingly.

Recommendation

Apply a workaround by removing or modifying the tool_choice block in the openai-codex image generation plugin, and then verify the updated plugin against the live Codex backend.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

One of the following should work reliably for the openai-codex image-gen plugin:

  1. The bundled/original request shape should be accepted by the live Codex backend and return an image_generation_call item/result, or
  2. The plugin should be updated to the currently supported request shape for Codex image generation so that Hermes can actually receive image events/results.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix bug(image-gen): openai-codex gpt-image-2 fails with tool_choice 400, then empty_response without image_generation_call [1 pull requests, 1 participants]