Skip to content

About

Lightweight OpenAI-compatible image generation & editing proxy (/v1/images/generations & /edits) backed by multi-account ChatGPT/Codex OAuth pools.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Codex ImageGen

MIT License Docker GHCR OpenAI Compatible

Lightweight OpenAI-compatible image generation & editing proxy (/v1/images/generations & /v1/images/edits) with multi-account OAuth rotation and a password-protected Management Web UI.


What You Get

  • Drop-In OpenAI Images API: Works with any OpenAI SDK or client supporting /v1/images/generations and multipart /v1/images/edits (up to 5 reference images, 10 MB each).
  • Multi-Account OAuth Pool: Automatically rotates across multiple ChatGPT/Codex OAuth accounts with built-in cooldown handling on rate limits.
  • Browser Management UI (/management): View pool health, generate manual PKCE OAuth login links, import auth.json, or harvest mounted credentials—all behind a signed HttpOnly session cookie.
  • Hardened Docker & Portainer Ready: Runs as non-root (node, UID 1000), supports read-only root filesystem, and keeps all credentials strictly in a persistent /data volume.

Quick Start

Prerequisite: Docker / Docker Compose or Portainer.

1. Deploy with Docker

Create .env.docker from .env.docker.example and set strong random values for PROXY_API_KEY, MANAGEMENT_PASSWORD, and MANAGEMENT_SESSION_SECRET:

cp .env.docker.example .env.docker
docker pull ghcr.io/ngojclee/codex-imagegen:latest

docker run -d --name codex-imagegen \
  -p 3456:3456 \
  --env-file .env.docker \
  --read-only \
  --tmpfs /tmp \
  --security-opt no-new-privileges:true \
  -v /path/to/codex-imagegen/data:/data \
  ghcr.io/ngojclee/codex-imagegen:latest

(For Portainer, paste deploy/portainer-stack.yml and deploy/portainer.env.example, and ensure the host data folder is owned by UID 1000 with chmod 700.)

2. Add Your First Account

  1. Open http://<your-host>:3456/management and sign in with MANAGEMENT_PASSWORD.
  2. Click Create Login Link, sign in via your browser, and copy the full callback URL (code=...&state=...) from the address bar (it is normal for the callback page itself to show connection refused).
  3. Paste the callback URL into Callback URL and click Complete Login (or paste an existing auth.json in Import Auth).

3. Generate & Edit Images

# Text-to-image
curl -X POST http://<your-host>:3456/v1/images/generations \
  -H "Authorization: Bearer <PROXY_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{"prompt":"a cinematic fantasy city at sunrise"}'

# Image edits (multipart)
curl -X POST http://<your-host>:3456/v1/images/edits \
  -H "Authorization: Bearer <PROXY_API_KEY>" \
  -F "prompt=Apply the style from the first image onto the second" \
  -F "image[]=@source.png;type=image/png" \
  -F "image[]=@target.png;type=image/png"

Security & Privacy

  • Strong Secret Separation: Set unique values for PROXY_API_KEY, MANAGEMENT_PASSWORD, and MANAGEMENT_SESSION_SECRET; keep ADMIN_API_KEY empty unless you explicitly need /admin/* automation.
  • Session & CSRF Protection: Management UI uses HttpOnly signed cookies and requires x-codex-imagegen-csrf: 1 on mutating requests.
  • Protect /management & /data: Place /management behind VPN, Tailscale, Cloudflare Access, or an HTTPS reverse proxy, and never commit .env or /data (which stores OAuth refresh tokens).

Advanced & Developer Reference (API Fields, Admin Endpoints, Environment Variables & Troubleshooting)

Endpoints

  • GET /health — Health check
  • GET /management — Browser Management UI
  • POST /v1/images/generations — JSON fields: prompt (required), model, input_refs, timeout_ms, size, quality, background, n
  • POST /v1/images/edits — Multipart fields: prompt, image[] / image (max 5 files, 10 MB each)
  • Optional Admin API (requires ADMIN_API_KEY): GET /admin/accounts, POST /admin/harvest, POST /admin/accounts/:id/revive, DELETE /admin/accounts/:id

Environment Variables

Variable Default Notes
PROXY_API_KEY (required in Docker) Bearer token for /v1/images/*
MANAGEMENT_PASSWORD (empty = disabled) Password for /management UI
MANAGEMENT_SESSION_SECRET (required with UI) HMAC secret for signed session cookies
MANAGEMENT_COOKIE_SECURE false Set true behind HTTPS
ADMIN_API_KEY (empty = disabled) Enables /admin/* endpoints
PORT 3456 Container listen port
DEFAULT_MODEL gpt-5.4 Default upstream model
DEFAULT_TIMEOUT_MS 900000 Request timeout
COOLDOWN_DEFAULT_MS 60000 Account cooldown after 429/403
OAUTH_REDIRECT_URI http://localhost:1455/auth/callback Manual PKCE OAuth redirect URI

Local Development & Troubleshooting

npm install
npm start
  • unauthorized pulling GHCR image: Authenticate ghcr.io with a GitHub PAT having read:packages (or make the GHCR package public).
  • Container cannot write to /data: Ensure chown -R 1000:1000 <data-dir> && chmod 700 <data-dir>.
  • /management says disabled: Set MANAGEMENT_PASSWORD and redeploy.

License

Licensed under the MIT License.

About

Lightweight OpenAI-compatible image generation & editing proxy (/v1/images/generations & /edits) backed by multi-account ChatGPT/Codex OAuth pools.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages