openclaw - 💡(How to fix) Fix [Windows] gpt-image-2 falls back to Codex route despite no Codex OAuth configured (HTTP 400) [1 comments, 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
openclaw/openclaw#72202Fetched 2026-04-27 05:33:24
View on GitHub
Comments
1
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
commented ×1

Error Message

OpenAI Codex image generation failed (HTTP 400): Tool choice 'image_generation' not found in 'tools' parameter. [type=invalid_request_error]

This error comes from the Codex Responses API (/v1/responses), not the Images API. The model gpt-image-2 should be called via POST /v1/images/generations.

Fix Action

Workaround

openai/gpt-image-1 works correctly via the Images API route.

Code Example

OpenAI Codex image generation failed (HTTP 400): Tool choice 'image_generation' not found in 'tools' parameter. [type=invalid_request_error]
RAW_BUFFERClick to expand / collapse

Environment

  • OS: Windows 11 (x64)
  • OpenClaw version: 2026.4.24
  • Node: v22.22.2

Problem

When using openai/gpt-image-2 for image generation, OpenClaw routes the request through the Codex Responses API instead of the Images API (/v1/images/generations), even though:

  • No openai-codex OAuth profile is configured
  • OPENAI_API_KEY is set in env section
  • gpt-image-1 works correctly via the Images API

Error

OpenAI Codex image generation failed (HTTP 400): Tool choice 'image_generation' not found in 'tools' parameter. [type=invalid_request_error]

This error comes from the Codex Responses API (/v1/responses), not the Images API. The model gpt-image-2 should be called via POST /v1/images/generations.

Steps to Reproduce

  1. Set OPENAI_API_KEY in openclaw.json env section
  2. Set agents.defaults.imageGenerationModel.primary to openai/gpt-image-2
  3. Restart gateway
  4. Call image_generate with model: openai/gpt-image-2
  5. Observe Codex route error

What I Tried

  1. Setting models.providers.openai.apiKeyEnvVar — gets wiped on gateway restart
  2. Setting models.providers.openai.baseUrl to https://api.openai.com/v1 — also gets wiped on restart
  3. openclaw doctor — reports no issues
  4. Manual verification — calling POST /v1/images/generations with gpt-image-2 directly via PowerShell works fine with the same API key

Expected Behavior

gpt-image-2 should use the Images API endpoint (/v1/images/generations) when OPENAI_API_KEY is configured and no Codex OAuth profile exists.

Additional Context

  • image_generate action=list shows: openai (default gpt-image-2) configured: yes
  • models.providers.openai config entries are cleared on every gateway restart
  • The openclaw.json file is overwritten during restart, removing the openai provider entry
  • Auth profiles: google:default, zai:default, google-gemini-cli (no Codex OAuth)

Workaround

openai/gpt-image-1 works correctly via the Images API route.

extent analysis

TL;DR

Configure the models.providers.openai settings in a way that persists across gateway restarts to ensure gpt-image-2 uses the Images API.

Guidance

  • Verify that the openclaw.json file is not being overwritten during restart, potentially by adjusting the configuration loading mechanism.
  • Investigate why models.providers.openai config entries are cleared on every gateway restart and find a way to make these settings persistent.
  • Consider setting up a separate configuration file or mechanism that is not affected by the gateway restart process.
  • Test configuring models.providers.openai.baseUrl to https://api.openai.com/v1 and models.providers.openai.apiKeyEnvVar to a fixed value to see if this forces the use of the Images API for gpt-image-2.

Example

No specific code example can be provided without more details on the configuration file format and the restart mechanism of the gateway.

Notes

The issue seems to stem from the configuration being lost on restart. Finding a way to persist the models.providers.openai settings is crucial. The provided workaround of using openai/gpt-image-1 may not be suitable for all use cases, especially if gpt-image-2 is required.

Recommendation

Apply a workaround by configuring the models.providers.openai settings in a persistent manner, as directly fixing the restart issue may require deeper changes to the gateway's configuration management.

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…

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 [Windows] gpt-image-2 falls back to Codex route despite no Codex OAuth configured (HTTP 400) [1 comments, 1 participants]