Repository navigation
Description
Client or integration
Codex CLI using the built-in image_gen tool through OpenCodex.
Provider or upstream service
A private OpenAI-compatible gateway. Its name, hostname, credentials, and models are intentionally omitted. The gateway accepts authenticated POST /v1/images/generations requests and returns the standard image response shape.
OpenCodex version
2.7.41
Endpoint or capability
Built-in image generation: POST /v1/images/generations.
Current behaviour
The proxy route itself exists, but the Images relay only selects two reserved OpenAI provider ids:
openaifor ChatGPT forwardingopenai-apikeyfor the official OpenAI API-key tier
A custom openai-responses provider is therefore ignored by the Images relay even when it supports /v1/images/generations.
Using the openai-apikey reserved id is not a usable workaround. Its registry entry pins the effective base URL to https://api.openai.com/v1; a configured gateway base URL is discarded at runtime. The gateway key is then sent to the official OpenAI endpoint and the request returns 401 invalid_api_key.
This produces two failure modes for the same gateway:
- With only a custom provider configured, built-in image generation returns
400because no usable OpenAI upstream is found. - After copying that configuration to
openai-apikey, the proxy sends the request toapi.openai.cominstead of the configured gateway and returns401.
The upstream gateway is not the issue: a direct, redacted request to its /v1/images/generations endpoint succeeds.
Expected behaviour
A user should be able to explicitly select a custom OpenAI-compatible provider for the Images relay when that provider supports the Images API and has an API key configured.
The selected provider's configured baseUrl must be used. OpenCodex should not route a custom gateway credential to the official OpenAI endpoint.
Minimal redacted reproduction
{
"providers": {
"custom-openai-compatible": {
"adapter": "openai-responses",
"authMode": "key",
"baseUrl": "https://gateway.example.com/v1",
"apiKey": "${IMAGE_GATEWAY_API_KEY}"
}
}
}# Direct upstream request: succeeds.
curl https://gateway.example.com/v1/images/generations \
-H "Authorization: Bearer $IMAGE_GATEWAY_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"model":"image-model","prompt":"test"}'
# Through OpenCodex: built-in image_gen reaches the local proxy,
# but the custom provider is not selected for the Images relay.Attempted workaround:
{
"providers": {
"openai-apikey": {
"adapter": "openai-responses",
"authMode": "key",
"baseUrl": "https://gateway.example.com/v1",
"apiKey": "${IMAGE_GATEWAY_API_KEY}"
}
}
}Actual response or error
With only the custom provider:
400 invalid_request_error
Built-in image generation needs an OpenAI upstream (ChatGPT login or an OpenAI API-key provider), but none is configured in opencodex.
With the openai-apikey workaround, the proxy logs that the configured base URL is ignored because the provider endpoint is fixed at https://api.openai.com/v1, followed by:
401 invalid_api_key
Incorrect API key provided
Upstream documentation
No public upstream documentation is available. The capability was verified with a direct request using the OpenAI Images API request and response format. All endpoint, credential, and provider-identifying details have been redacted.
Suggested mapping or implementation notes
Please consider adding an explicit Images relay provider selection, for example:
{
"images": {
"provider": "custom-openai-compatible"
}
}Suggested behavior:
- Keep the current
openai/openai-apikeybehavior as the backward-compatible default whenimages.provideris unset. - When set, resolve the named provider from
config.providersand use its configuredbaseUrland API key for/v1/images/generationsand/v1/images/edits. - Validate that the provider exists, is enabled, uses a compatible OpenAI-style adapter/auth mode, and has a usable credential. Return a clear
400if it does not. - Keep
openai-apikeypinned to the official API if that is intentional. A dedicated explicit selector avoids weakening registry invariants or overloading the official provider id. - Add regression tests that verify a custom provider receives the Images request at its configured base URL, plus tests for invalid provider selection and the existing default fallback behaviour.
- Document that the configured provider must implement the OpenAI Images API response shape expected by Codex.
Related but distinct issues:
- Built-in image generation returns
404 Unknown endpoint#83 added the/v1/images/generationsand/v1/images/editsproxy routes. This report concerns upstream provider selection after those routes are reached. - alibaba-token-plan registry entry silently overrides saved baseUrl -> 401 after provider migration #457 covers registry entries discarding an overridden base URL. This report needs a supported, durable custom-provider path for image generation rather than relying on the reserved
openai-apikeyid.
Additional context
Environment: macOS 26.5, arm64; Codex CLI 0.145.0.
I searched the existing provider-compatibility and image-generation issues. No secret, internal hostname, account identifier, model identifier, local path, or credential is included in this report.
Activity
github-actions commentedon Jul 27, 2026
Ingwannu commentedon Jul 27, 2026
Confirmed against current
dev: the report is valid, and the explicitimages.providerdirection in #551 is the right compatibility-preserving fix. I reviewed and ran its current head locally (Images tests 26/26 plus typecheck).I have requested two corrections before merge: allow the normal Bearer-form OpenCodex admission credential when an explicit keyed Images provider will replace it before the upstream request, and remove the unsupported claim that multipart edit bodies are currently forwarded unchanged. The existing ChatGPT/OpenAI fallback and registry-managed provider protections should stay unchanged.
Tracking the implementation in #551; I will close this issue only after the corrected PR lands on
dev.lidge-jun commentedon Jul 27, 2026
Fixed by PR #551, merged into dev at 14ae6fe.\n\nVerified before merge on current PR head f51b64a:\n- explicit custom Images provider supports keyed OpenAI-compatible /v1/images/generations routing\n- Bearer OpenCodex admission is accepted only after explicit keyed provider selection, and the proxy secret is not forwarded upstream\n- invalid explicit Images provider configuration returns 400 before admission masking\n- multipart forwarding claim narrowed to JSON Images requests\n\nLocal verification: bun test tests/server-images.test.ts = 28 pass / 0 fail; bun x tsc --noEmit pass; bun run privacy:scan pass; git diff --check pass.