openclaw - 💡(How to fix) Fix [Bug]: openai/gpt-image-2 via Codex OAuth fails with missing image scope [2 comments, 3 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#70885Fetched 2026-04-24 10:38:19
View on GitHub
Comments
2
Participants
3
Timeline
5
Reactions
0
Author
Timeline (top)
commented ×2labeled ×2cross-referenced ×1

OpenAI image generation with openai/gpt-image-2 fails through Codex OAuth because the OAuth token lacks api.model.images.request, and the shipped OAuth client is rejected when that scope is requested.

Error Message

Root Cause

OpenAI image generation with openai/gpt-image-2 fails through Codex OAuth because the OAuth token lacks api.model.images.request, and the shipped OAuth client is rejected when that scope is requested.

Fix Action

Fix / Workaround

  1. Configure OpenClaw 2026.4.22 with agents.defaults.imageGenerationModel.primary = "openai/gpt-image-2" and an openai-codex OAuth profile.
  2. Do not configure a custom models.providers.openai API key or base URL.
  3. Run an image generation request, for example: openclaw infer image generate --model openai/gpt-image-2 --prompt "A friendly robot mascot" --count 1 --size 1024x1024 --output /tmp/openclaw-image-test.png --json.
  4. Observe that the OpenAI image request fails with HTTP 401 due to missing api.model.images.request.
  5. As a control, patch the local Codex OAuth scope to include api.model.images.request and retry login.
  6. Observe OpenAI rejects the OAuth request with invalid_scope, stating the OAuth client is not allowed to request that scope.

Patched local OAuth scope in:

Code Example

Observed OpenAI Images API failure:

`OpenAI image generation failed (HTTP 401): Missing scopes: api.model.images.request`

Control test:

Patched local OAuth scope in:

`/opt/homebrew/lib/node_modules/openclaw/node_modules/@mariozechner/pi-ai/dist/utils/oauth/openai-codex.js`

from:

`const SCOPE = "openid profile email offline_access";`

to:

`const SCOPE = "openid profile email offline_access api.model.images.request";`

The resulting authorize URL included `api.model.images.request`, but OpenAI rejected the callback with:

`error=invalid_scope`

Browser page showed:

`Authentication failed`
`Missing authorization code`

The callback URL contained:

`error=invalid_scope&error_description=The requested scope is invalid, unknown, or malformed. The OAuth 2.0 Client is not allowed to request...`

Attached screenshot shows the `invalid_scope` callback/authentication failure.

http://localhost:1455/auth/callback?error=invalid_scope&error_description=The+requested+scope+is+invalid%2C+unknown%2C+or+malformed.+The+OAuth+2.0+Client+is+not+allowed+to+request+scope+%27api.model.images.request%27.&state=71a5a5cad9ead8f67ee5bd2d05ca39dc
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

OpenAI image generation with openai/gpt-image-2 fails through Codex OAuth because the OAuth token lacks api.model.images.request, and the shipped OAuth client is rejected when that scope is requested.

Steps to reproduce

  1. Configure OpenClaw 2026.4.22 with agents.defaults.imageGenerationModel.primary = "openai/gpt-image-2" and an openai-codex OAuth profile.
  2. Do not configure a custom models.providers.openai API key or base URL.
  3. Run an image generation request, for example: openclaw infer image generate --model openai/gpt-image-2 --prompt "A friendly robot mascot" --count 1 --size 1024x1024 --output /tmp/openclaw-image-test.png --json.
  4. Observe that the OpenAI image request fails with HTTP 401 due to missing api.model.images.request.
  5. As a control, patch the local Codex OAuth scope to include api.model.images.request and retry login.
  6. Observe OpenAI rejects the OAuth request with invalid_scope, stating the OAuth client is not allowed to request that scope.

Expected behavior

openai/gpt-image-2 should generate an image through the configured openai-codex OAuth profile without requiring OPENAI_API_KEY, matching the documented OAuth routing behavior.

Actual behavior

The image request fails with HTTP 401 because the Codex OAuth token does not include api.model.images.request. When api.model.images.request is added to the local OAuth scope and login is retried, OpenAI rejects the authorization request with invalid_scope.

OpenClaw version

2026.4.22

Operating system

macOS 26.4 (25E246)

Install method

npm global install via Homebrew Node (/opt/homebrew/bin/openclaw, package [email protected])

Model

openai/gpt-image-2

Provider / routing chain

openai/gpt-image-2 image generation provider using openai-codex OAuth profile; no custom models.providers.openai API key or baseUrl configured

Additional provider/model setup details

openclaw infer image providers reports the OpenAI image provider as configured: true, selected: true, with defaultModel: "gpt-image-2".

Config includes:

agents.defaults.imageGenerationModel.primary = "openai/gpt-image-2"

Auth includes an openai-codex OAuth profile. No custom models.providers.openai API key or base URL is configured for the OpenAI image route.

Logs, screenshots, and evidence

Observed OpenAI Images API failure:

`OpenAI image generation failed (HTTP 401): Missing scopes: api.model.images.request`

Control test:

Patched local OAuth scope in:

`/opt/homebrew/lib/node_modules/openclaw/node_modules/@mariozechner/pi-ai/dist/utils/oauth/openai-codex.js`

from:

`const SCOPE = "openid profile email offline_access";`

to:

`const SCOPE = "openid profile email offline_access api.model.images.request";`

The resulting authorize URL included `api.model.images.request`, but OpenAI rejected the callback with:

`error=invalid_scope`

Browser page showed:

`Authentication failed`
`Missing authorization code`

The callback URL contained:

`error=invalid_scope&error_description=The requested scope is invalid, unknown, or malformed. The OAuth 2.0 Client is not allowed to request...`

Attached screenshot shows the `invalid_scope` callback/authentication failure.

http://localhost:1455/auth/callback?error=invalid_scope&error_description=The+requested+scope+is+invalid%2C+unknown%2C+or+malformed.+The+OAuth+2.0+Client+is+not+allowed+to+request+scope+%27api.model.images.request%27.&state=71a5a5cad9ead8f67ee5bd2d05ca39dc

Impact and severity

Affected users/systems/channels: Users attempting to use openai/gpt-image-2 image generation through openai-codex OAuth.

Severity: Blocks the documented OAuth-based OpenAI image generation workflow.

Frequency: Always observed in this tested configuration.

Consequence: Users must either configure a direct OPENAI_API_KEY route or use another image provider, despite docs indicating Codex OAuth should work.

Additional information

OpenClaw version tested: 2026.4.22 (00bd2cf).

The issue was reproduced after validating openclaw.json and confirming the gateway was running. openclaw config validate passed.

The OpenAI image auth resolver appears to fall back to openai-codex OAuth, but the resulting token is not accepted by the OpenAI Images API because it lacks api.model.images.request.

lobster-biscuit

extent analysis

TL;DR

The most likely fix is to update the OAuth scope of the openai-codex profile to include api.model.images.request, but this may require changes to the OpenAI OAuth client configuration.

Guidance

  • Verify that the openai-codex OAuth profile is correctly configured and that the scope includes api.model.images.request.
  • Check the OpenAI OAuth client settings to ensure that it is allowed to request the api.model.images.request scope.
  • Consider using a custom models.providers.openai API key or base URL as a workaround, if possible.
  • Review the OpenClaw documentation to see if there are any specific requirements or restrictions for using openai/gpt-image-2 with openai-codex OAuth.

Example

No code snippet is provided as the issue is related to configuration and OAuth settings.

Notes

The issue may be specific to the openai-codex OAuth profile and the OpenAI Images API, and may require changes to the OAuth client configuration or the use of a custom API key.

Recommendation

Apply a workaround by using a custom models.providers.openai API key or base URL, if possible, as the current OAuth client configuration may not be compatible with the required scope.

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

openai/gpt-image-2 should generate an image through the configured openai-codex OAuth profile without requiring OPENAI_API_KEY, matching the documented OAuth routing behavior.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING