Skip to content

feat(codex): add Images API routes for gpt-image-2 generation and edits - #85

Merged
raine merged 2 commits into
raine:mainfrom
biuworks:feature/codex-images
Jul 29, 2026
Merged

feat(codex): add Images API routes for gpt-image-2 generation and edits#85
raine merged 2 commits into
raine:mainfrom
biuworks:feature/codex-images

Conversation

@biuworks

Copy link
Copy Markdown
Contributor

Summary

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).

Motivation

Codex SDK includes a built-in image_gen tool that calls these endpoints. Without them, image generation through the proxy is not possible — the SDK falls back to requiring OPENAI_API_KEY and direct API calls.

Changes

New file: src/providers/codex/images.rs

  • CodexImagesBackend with 2-concurrent-request limiter
  • JSON generation/edit request parsing with strict validation
  • Multipart/form-data edit support (OpenAI-style), translated to Codex data URLs
  • Magic-byte image type detection (PNG/JPEG/GIF/WebP)
  • Upstream host locked to chatgpt.com/backend-api/codex
  • Size limits: 256KB generation, 64MB multipart edit, 20MB per image, 128MB response

Modified: src/providers/codex/client.rs

  • build_codex_image_headers() — dedicated OAuth headers for image requests
  • post_image_json() + attempt_image_json() — with 401 auto-refresh
  • IMAGE_HEADER_TIMEOUT_MS = 300s — image generation latency is 60-120s, needs longer than default 60s header timeout

Modified: src/server.rs

  • Route /v1/images/generations and /v1/images/edits (only when imagesApi: true)
  • dispatch_image_request() — unified handler for JSON + multipart
  • No query parameters, no masks, no variations (returns 4xx)

Config: src/config.rs

  • codex_images_api()CCP_CODEX_IMAGES_API env or codex.imagesApi config
  • codex_images_base_url()CCP_CODEX_IMAGES_BASE_URL env, defaults to chatgpt.com

Other

  • EndpointKind::Images in monitor
  • Full test coverage (validation, error types, multipart, size limits)
  • Docs updated: http-api.md, configuration.md, compatibility-and-limitations.md, codex.md, README, CHANGELOG

Testing

  • All 28 existing tests pass
  • Manually tested /v1/images/generations with CCP_CODEX_IMAGES_API=1 — returns 200 with valid base64 PNG
  • Codex review passed with no findings

Notes

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

biuworks and others added 2 commits July 29, 2026 16:45
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
raine force-pushed the feature/codex-images branch from 02d955e to 9581a15 Compare July 29, 2026 14:46
@raine
raine merged commit 0d1c022 into raine:main Jul 29, 2026
@raine

raine commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Thank you

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants