Skip to content

Image relay cannot use a custom OpenAI-compatible provider with /v1/images/generations #549

Closed

Description

@iF2007

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:

  • openai for ChatGPT forwarding
  • openai-apikey for 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:

  1. With only a custom provider configured, built-in image generation returns 400 because no usable OpenAI upstream is found.
  2. After copying that configuration to openai-apikey, the proxy sends the request to api.openai.com instead of the configured gateway and returns 401.

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:

  1. Keep the current openai / openai-apikey behavior as the backward-compatible default when images.provider is unset.
  2. When set, resolve the named provider from config.providers and use its configured baseUrl and API key for /v1/images/generations and /v1/images/edits.
  3. Validate that the provider exists, is enabled, uses a compatible OpenAI-style adapter/auth mode, and has a usable credential. Return a clear 400 if it does not.
  4. Keep openai-apikey pinned to the official API if that is intentional. A dedicated explicit selector avoids weakening registry invariants or overloading the official provider id.
  5. 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.
  6. Document that the configured provider must implement the OpenAI Images API response shape expected by Codex.

Related but distinct issues:

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

  1. added
    provider-compatibility
    on Jul 27, 2026
  2. github-actions commented on Jul 27, 2026

    @github-actions
    Contributor
  3. Ingwannu commented on Jul 27, 2026

    @Ingwannu
    Owner

    Confirmed against current dev: the report is valid, and the explicit images.provider direction 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.

  4. lidge-jun commented on Jul 27, 2026

    @lidge-jun
    Owner

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    provider-compatibility

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions