feat(codex): add Images API routes for gpt-image-2 generation and edits - #85
Merged
Conversation
Add optional /v1/images/generations and /v1/images/edits endpoints that reuse the existing ChatGPT OAuth session. The feature is gated behind CCP_CODEX_IMAGES_API=1 (or codex.imagesApi in config). - New CodexImagesBackend with bounded JSON/multipart parsing, upstream validation, and 2-concurrent-request limiter - Enforce chatgpt.com-only upstream, strict size limits, and diagnostic privacy (no image base64 in traffic captures) - Accept multipart/form-data edits with image/image[] files (OpenAI-style compatibility), translated to Codex data URLs - IMAGE_HEADER_TIMEOUT_MS=300s to avoid 502 on slow image generation - Full test coverage: validation, error types, multipart, size limits
Apply rustfmt to the image backend and server integration tests so the required format check accepts the Images API patch. This changes layout only and does not alter request handling or API behavior.
raine
force-pushed
the
feature/codex-images
branch
from
July 29, 2026 14:46
02d955e to
9581a15
Compare
Owner
|
Thank you |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add optional
/v1/images/generationsand/v1/images/editsendpoints that reuse the existing ChatGPT OAuth session. The feature is gated behindCCP_CODEX_IMAGES_API=1(orcodex.imagesApiin config).Motivation
Codex SDK includes a built-in
image_gentool that calls these endpoints. Without them, image generation through the proxy is not possible — the SDK falls back to requiringOPENAI_API_KEYand direct API calls.Changes
New file:
src/providers/codex/images.rsCodexImagesBackendwith 2-concurrent-request limiterchatgpt.com/backend-api/codexModified:
src/providers/codex/client.rsbuild_codex_image_headers()— dedicated OAuth headers for image requestspost_image_json()+attempt_image_json()— with 401 auto-refreshIMAGE_HEADER_TIMEOUT_MS = 300s— image generation latency is 60-120s, needs longer than default 60s header timeoutModified:
src/server.rs/v1/images/generationsand/v1/images/edits(only whenimagesApi: true)dispatch_image_request()— unified handler for JSON + multipartConfig:
src/config.rscodex_images_api()—CCP_CODEX_IMAGES_APIenv orcodex.imagesApiconfigcodex_images_base_url()—CCP_CODEX_IMAGES_BASE_URLenv, defaults to chatgpt.comOther
EndpointKind::Imagesin monitorTesting
/v1/images/generationswithCCP_CODEX_IMAGES_API=1— returns 200 with valid base64 PNGNotes
Images API is an internal ChatGPT Codex integration, not the public OpenAI Platform Images API. It consumes the signed-in ChatGPT account's entitlement and quota.
🤖 Generated with Claude Code