fix(openai): reuse Codex OAuth for OpenAI images

This commit is contained in:
Peter Steinberger
2026-04-23 22:06:28 +01:00
parent f1ad5e27e0
commit ddcc39de91
8 changed files with 189 additions and 212 deletions

View File

@@ -184,16 +184,17 @@ Choose your preferred auth method and follow the setup steps.
The bundled `openai` plugin registers image generation through the `image_generate` tool.
It supports both OpenAI API-key image generation and Codex OAuth image
generation.
generation through the same `openai/gpt-image-2` model ref.
| Capability | OpenAI API key | Codex OAuth |
| ------------------------- | ---------------------------------- | ---------------------------------- |
| Model ref | `openai/gpt-image-2` | `openai-codex/gpt-image-2` |
| Auth | `OPENAI_API_KEY` | OpenAI Codex OAuth sign-in |
| Max images per request | 4 | 4 |
| Edit mode | Enabled (up to 5 reference images) | Enabled (up to 5 reference images) |
| Size overrides | Supported, including 2K/4K sizes | Supported, including 2K/4K sizes |
| Aspect ratio / resolution | Not forwarded to OpenAI Images API | Mapped to supported size when safe |
| Capability | OpenAI API key | Codex OAuth |
| ------------------------- | ---------------------------------- | ------------------------------------ |
| Model ref | `openai/gpt-image-2` | `openai/gpt-image-2` |
| Auth | `OPENAI_API_KEY` | OpenAI Codex OAuth sign-in |
| Transport | OpenAI Images API | Codex Responses backend |
| Max images per request | 4 | 4 |
| Edit mode | Enabled (up to 5 reference images) | Enabled (up to 5 reference images) |
| Size overrides | Supported, including 2K/4K sizes | Supported, including 2K/4K sizes |
| Aspect ratio / resolution | Not forwarded to OpenAI Images API | Mapped to a supported size when safe |
```json5
{
@@ -205,18 +206,6 @@ generation.
}
```
Use Codex OAuth instead:
```json5
{
agents: {
defaults: {
imageGenerationModel: { primary: "openai-codex/gpt-image-2" },
},
},
}
```
<Note>
See [Image Generation](/tools/image-generation) for shared tool parameters, provider selection, and failover behavior.
</Note>
@@ -225,12 +214,10 @@ See [Image Generation](/tools/image-generation) for shared tool parameters, prov
editing. `gpt-image-1` remains usable as an explicit model override, but new
OpenAI image workflows should use `openai/gpt-image-2`.
The `openai-codex` provider also exposes `gpt-image-2` for image generation and
reference-image editing through OpenAI Codex OAuth. Use
`openai-codex/gpt-image-2` when the agent is signed in with Codex OAuth but does
not have an `OPENAI_API_KEY`. OpenClaw resolves the stored Codex OAuth access
token for `openai-codex` and sends image requests through the Codex Responses
backend, so this path works without the public OpenAI Images API key.
For Codex OAuth installs, keep the same `openai/gpt-image-2` ref. If no
`OPENAI_API_KEY` is available, OpenClaw resolves the stored OAuth access token
for the `openai-codex` auth profile and sends image requests through the Codex
Responses backend, so this path works without the public OpenAI Images API key.
Generate:
@@ -238,18 +225,6 @@ Generate:
/tool image_generate model=openai/gpt-image-2 prompt="A polished launch poster for OpenClaw on macOS" size=3840x2160 count=1
```
Generate with Codex OAuth:
```
/tool image_generate model=openai-codex/gpt-image-2 prompt="A polished launch poster for OpenClaw on macOS" size=3840x2160 count=1
```
Edit with Codex OAuth:
```
/tool image_generate model=openai-codex/gpt-image-2 prompt="Preserve the object shape, change the material to translucent glass" image=/path/to/reference.png size=1024x1536
```
Edit:
```

View File

@@ -30,36 +30,25 @@ The tool only appears when at least one image generation provider is available.
}
```
Use Codex OAuth instead of an OpenAI API key:
Codex OAuth uses the same `openai/gpt-image-2` model ref. If no `OPENAI_API_KEY`
is available, OpenClaw resolves the existing `openai-codex` OAuth profile and
sends the image request through the Codex Responses backend.
```json5
{
agents: {
defaults: {
imageGenerationModel: {
primary: "openai-codex/gpt-image-2",
},
},
},
}
```
3. Ask the agent: _"Generate an image of a friendly lobster mascot."_
3. Ask the agent: _"Generate an image of a friendly robot mascot."_
The agent calls `image_generate` automatically. No tool allow-listing needed — it's enabled by default when a provider is available.
## Supported providers
| Provider | Default model | Edit support | API key |
| ------------ | -------------------------------- | ---------------------------------- | ----------------------------------------------------- |
| OpenAI | `gpt-image-2` | Yes (up to 4 images) | `OPENAI_API_KEY` |
| OpenAI Codex | `gpt-image-2` | Yes (up to 4 images) | OpenAI Codex OAuth |
| Google | `gemini-3.1-flash-image-preview` | Yes | `GEMINI_API_KEY` or `GOOGLE_API_KEY` |
| fal | `fal-ai/flux/dev` | Yes | `FAL_KEY` |
| MiniMax | `image-01` | Yes (subject reference) | `MINIMAX_API_KEY` or MiniMax OAuth (`minimax-portal`) |
| ComfyUI | `workflow` | Yes (1 image, workflow-configured) | `COMFY_API_KEY` or `COMFY_CLOUD_API_KEY` for cloud |
| Vydra | `grok-imagine` | No | `VYDRA_API_KEY` |
| xAI | `grok-imagine-image` | Yes (up to 5 images) | `XAI_API_KEY` |
| Provider | Default model | Edit support | Auth |
| -------- | -------------------------------- | ---------------------------------- | ----------------------------------------------------- |
| OpenAI | `gpt-image-2` | Yes (up to 4 images) | `OPENAI_API_KEY` or OpenAI Codex OAuth |
| Google | `gemini-3.1-flash-image-preview` | Yes | `GEMINI_API_KEY` or `GOOGLE_API_KEY` |
| fal | `fal-ai/flux/dev` | Yes | `FAL_KEY` |
| MiniMax | `image-01` | Yes (subject reference) | `MINIMAX_API_KEY` or MiniMax OAuth (`minimax-portal`) |
| ComfyUI | `workflow` | Yes (1 image, workflow-configured) | `COMFY_API_KEY` or `COMFY_CLOUD_API_KEY` for cloud |
| Vydra | `grok-imagine` | No | `VYDRA_API_KEY` |
| xAI | `grok-imagine-image` | Yes (up to 5 images) | `XAI_API_KEY` |
Use `action: "list"` to inspect available providers and models at runtime:
@@ -73,7 +62,7 @@ Use `action: "list"` to inspect available providers and models at runtime:
| ------------- | -------- | ------------------------------------------------------------------------------------- |
| `prompt` | string | Image generation prompt (required for `action: "generate"`) |
| `action` | string | `"generate"` (default) or `"list"` to inspect providers |
| `model` | string | Provider/model override, e.g. `openai/gpt-image-2` or `openai-codex/gpt-image-2` |
| `model` | string | Provider/model override, e.g. `openai/gpt-image-2` |
| `image` | string | Single reference image path or URL for edit mode |
| `images` | string[] | Multiple reference images for edit mode (up to 5) |
| `size` | string | Size hint: `1024x1024`, `1536x1024`, `1024x1536`, `2048x2048`, `3840x2160` |
@@ -139,11 +128,12 @@ OpenAI, Google, and xAI support up to 5 reference images via the `images` parame
### OpenAI `gpt-image-2`
OpenAI image generation defaults to `openai/gpt-image-2` with `OPENAI_API_KEY`.
Use `openai-codex/gpt-image-2` to generate or edit images with the same Codex
OAuth sign-in used by `openai-codex` chat models. The older `openai/gpt-image-1`
model can still be selected explicitly, but new OpenAI image-generation and
image-editing requests should use `gpt-image-2`.
OpenAI image generation defaults to `openai/gpt-image-2`. It uses
`OPENAI_API_KEY` when available. If no API key is configured, OpenClaw reuses the
same `openai-codex` OAuth profile used by Codex subscription chat models and
sends the image request through the Codex Responses backend. The older
`openai/gpt-image-1` model can still be selected explicitly, but new OpenAI
image-generation and image-editing requests should use `gpt-image-2`.
`gpt-image-2` supports both text-to-image generation and reference-image
editing through the same `image_generate` tool. OpenClaw forwards `prompt`,
@@ -169,18 +159,6 @@ Edit one local reference image:
/tool image_generate action=generate model=openai/gpt-image-2 prompt="Keep the subject, replace the background with a bright studio setup" image=/path/to/reference.png size=1024x1536
```
Generate with Codex OAuth:
```
/tool image_generate action=generate model=openai-codex/gpt-image-2 prompt="A clean editorial poster for OpenClaw image generation" size=3840x2160 count=1
```
Edit one local reference image with Codex OAuth:
```
/tool image_generate action=generate model=openai-codex/gpt-image-2 prompt="Keep the subject, replace the background with a bright studio setup" image=/path/to/reference.png size=1024x1536
```
Edit with multiple references:
```