fix(images): support custom image relay providers - #551
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Ingwannu
left a comment
There was a problem hiding this comment.
The feature is worthwhile and the current implementation is focused. I verified the current head (35fb1f8b) locally: bun test tests/server-images.test.ts passes 26/26 and bun run typecheck passes. The duplicate-json review note is already stale on this head.
Two blockers remain before merge:
handleImages()callsvalidateForwardAdmissionCredential()before selecting the explicit keyed Images provider. On a non-loopback proxy, a client using the supportedAuthorization: Bearer <OpenCodex admission key>form therefore gets 401 even though the keyed provider path replaces that header with the provider key before fetch. Keep the admission secret fail-closed for ChatGPT/forward relays, but allow the explicit keyed path after selection and add a regression covering Bearer admission plusimages.providerwhile asserting the proxy secret never reaches upstream.structure/04_transports-and-sidecars.mdsays compatible multipart edits are forwarded unchanged, but the handler always usesreadJsonRequestBody()andJSON.stringify(body). Please narrow the invariant/docs to JSON Images requests in this PR unless multipart preservation is implemented and tested.
Once those are corrected and CI is green, this should be mergeable.
Allow standalone Images requests to explicitly select a custom API-key openai-responses provider while preserving the existing ChatGPT/OpenAI fallback. Fail closed for invalid selections and keep registry-managed provider endpoints protected.
|
Addressed both blockers in
Validation: |
050347f to
ab652af
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/server/images.ts (1)
51-70: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winReturn explicit-provider configuration errors before the forward-admission check.
On a non-loopback bind, an invalid
images.providerplusAuthorization: Bearer <OPENCODEX_API_AUTH_TOKEN>reaches Lines 53-58 first and returns401, hiding the intended400 invalid_request_errorfrom Lines 69-71. No upstream can be selected in this case, so the anti-forwarding guard is unnecessary. Checkcandidates.errorimmediately after selection, before admission validation, and add the remote-bearer regression case.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/server/images.ts` around lines 51 - 70, Move the candidates.error check in the image request flow immediately after selectImagesProvider(config), before validateForwardAdmissionCredential in the admission guard. Return the existing 400 invalid_request_error response for invalid explicit-provider configuration before any authentication check, while preserving normal admission validation for valid configurations. Add a regression case covering a non-loopback request with an invalid images.provider and a bearer token.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/server/images.ts`:
- Around line 51-70: Move the candidates.error check in the image request flow
immediately after selectImagesProvider(config), before
validateForwardAdmissionCredential in the admission guard. Return the existing
400 invalid_request_error response for invalid explicit-provider configuration
before any authentication check, while preserving normal admission validation
for valid configurations. Add a regression case covering a non-loopback request
with an invalid images.provider and a bearer token.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 6e143c2a-376f-4992-bda7-8069a33ec45d
📒 Files selected for processing (12)
docs-site/src/content/docs/guides/codex-integration.mddocs-site/src/content/docs/ja/guides/codex-integration.mddocs-site/src/content/docs/ko/guides/codex-integration.mddocs-site/src/content/docs/reference/configuration.mddocs-site/src/content/docs/ru/guides/codex-integration.mddocs-site/src/content/docs/zh-cn/guides/codex-integration.mdsrc/providers/openai-sidecar.tssrc/server/images.tssrc/types.tsstructure/01_runtime.mdstructure/04_transports-and-sidecars.mdtests/server-images.test.ts
|
Addressed the configuration-error ordering in
Validated with |
Summary
Adds an explicit
images.providersetting for Codex's standalone/v1/images/generationsand/v1/images/editsrelay.openai-responsesprovider only for Images requests.images.provideris omitted.openai-apikeytier.Fixes #549
Validation
bun test tests/server-images.test.ts tests/server-live.test.tsbun run typecheckbun run privacy:scanbun run test(4839 passed before rebasing this single commit onto currentdev)Security Notes
The configured provider key replaces the caller bearer before the upstream Images request. Existing provider destination validation, data-plane authentication, request limits, cancellation, and response-size protections remain unchanged.
Summary by CodeRabbit
imagesconfiguration to explicitly select a custom OpenAI-compatible Images provider for built-in image generation.