openclaw - 💡(How to fix) Fix Bug: openai/gpt-image-2 via Codex OAuth — Tool choice 'image_generation' not found in 'tools' parameter [1 comments, 2 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
openclaw/openclaw#75188Fetched 2026-05-01 05:37:10
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
2
Timeline (top)
mentioned ×2subscribed ×2closed ×1commented ×1

When using openai/gpt-image-2 for image generation with a valid openai-codex OAuth profile, OpenClaw routes the request to the Codex Responses API, but the request body is malformed: tool_choice is set to "image_generation" while the tools array is empty or missing the corresponding tool definition. This causes a 400 error from the Codex API.

Error Message

All image generation models failed (3): openai/gpt-image-2: OpenAI Codex image generation failed (HTTP 400): { "error": { "message": "Tool choice 'image_generation' not found in 'tools' parameter.", "type": "invalid_request_error", "param": "tool_choice", "code": null } }

Root Cause

When using openai/gpt-image-2 for image generation with a valid openai-codex OAuth profile, OpenClaw routes the request to the Codex Responses API, but the request body is malformed: tool_choice is set to "image_generation" while the tools array is empty or missing the corresponding tool definition. This causes a 400 error from the Codex API.

Code Example

All image generation models failed (3): openai/gpt-image-2: OpenAI Codex image generation failed (HTTP 400): { "error": { "message": "Tool choice 'image_generation' not found in 'tools' parameter.", "type": "invalid_request_error", "param": "tool_choice", "code": null } }
RAW_BUFFERClick to expand / collapse

Bug: openai/gpt-image-2 via Codex OAuth — "Tool choice 'image_generation' not found in 'tools' parameter"

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Environment

  • OS: macOS
  • OpenClaw version: 2026.4.27
  • Node: v25.8.1

Summary

When using openai/gpt-image-2 for image generation with a valid openai-codex OAuth profile, OpenClaw routes the request to the Codex Responses API, but the request body is malformed: tool_choice is set to "image_generation" while the tools array is empty or missing the corresponding tool definition. This causes a 400 error from the Codex API.

Steps to reproduce

  1. Configure OpenClaw 2026.4.27 with agents.defaults.imageGenerationModel.primary = "openai/gpt-image-2"
  2. Authenticate via openai-codex OAuth (valid token, works for text models)
  3. Call image_generate with any prompt, e.g. "A cute kitten"
  4. Observe the error below

Error

All image generation models failed (3): openai/gpt-image-2: OpenAI Codex image generation failed (HTTP 400): { "error": { "message": "Tool choice 'image_generation' not found in 'tools' parameter.", "type": "invalid_request_error", "param": "tool_choice", "code": null } }

Expected behavior

The Codex Responses API should receive a properly formed request where tool_choice: "image_generation" is accompanied by a tools array containing the image_generation tool definition.

Related issues

  • #70703 (Feature: support gpt-image-2 via Codex OAuth) — closed
  • #70885 (Bug: openai/gpt-image-2 via Codex OAuth fails with missing image scope) — closed fixed in 2026.4.23
  • #72202 (Windows: gpt-image-2 falls back to Codex route despite API key configured) — closed

Tags

  • image-generation
  • openai-codex
  • bug

extent analysis

TL;DR

The most likely fix is to ensure the tools array in the request body includes the image_generation tool definition when using openai/gpt-image-2 with Codex OAuth.

Guidance

  • Verify that the tools array is properly configured and includes the image_generation tool definition in the request body sent to the Codex Responses API.
  • Check the OpenClaw configuration to ensure that the imageGenerationModel is correctly set to "openai/gpt-image-2" and that the openai-codex OAuth profile is valid.
  • Review the request body formatting to ensure it matches the expected format for the Codex API, including the tool_choice and tools parameters.
  • Consider updating the OpenClaw version to the latest available, as the issue may have been addressed in a newer release.

Example

No code snippet is provided as the issue is related to the request body formatting and configuration.

Notes

The issue seems to be specific to the openai/gpt-image-2 model and Codex OAuth authentication. The provided error message and steps to reproduce suggest a configuration or request formatting issue.

Recommendation

Apply a workaround by manually ensuring the tools array includes the image_generation tool definition in the request body, as this is the most direct way to address the error message received from the Codex API.

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

The Codex Responses API should receive a properly formed request where tool_choice: "image_generation" is accompanied by a tools array containing the image_generation tool definition.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Bug: openai/gpt-image-2 via Codex OAuth — Tool choice 'image_generation' not found in 'tools' parameter [1 comments, 2 participants]