Generate and edit images from your terminal using Codex's built-in image tools β no API key needed.
Codex (OpenAI's CLI coding agent) has image generation capabilities built in. This CLI exposes them as a standalone scriptable tool, reusing your existing Codex ChatGPT login. Supports generate, edit, and batch modes out of the box.
$ codex-imagegen generate \
--prompt "A 32x32 retro RPG pixel icon of an iron helmet, no text" \
--out output/icons/iron-helmet.png
Uses your existing Codex ChatGPT login β no OPENAI_API_KEY required.
Codex (OpenAI's CLI coding agent) has image generation built in β but it's prompt-driven and agentic, not a scriptable command. There is no codex image generate subcommand, no --size or --quality flags, and the documented automation primitive (codex exec) emits assistant text, not image bytes.
This CLI fills that gap by calling Codex's backend directly, using your existing ChatGPT subscription auth. No OPENAI_API_KEY needed, as it's not API billing - just the same image generation Codex uses internally, exposed as a scriptable tool for generate, edit, and batch workflows with clear options for model, size, quality, background, and output.
- Python 3.10+
uv- Codex logged in with ChatGPT auth
Run Codex login once if needed:
codex loginChoose the ChatGPT login flow. The CLI reads $CODEX_HOME/auth.json or ~/.codex/auth.json, refreshes tokens when needed, and never prints token values.
Use the CLI from a local checkout:
git clone https://github.com/jdmnk/codex-imagegen-cli.git
cd codex-imagegen-cli
uv sync --devVerify the command:
uv run codex-imagegen --help
uv run codex-imagegen --versionRun a dry run:
uv run codex-imagegen generate \
--prompt "A 32x32 retro RPG pixel icon of an iron helmet, no text" \
--out output/icons/iron-helmet.png \
--dry-runTo install it as a user command from the checkout:
uv tool install -e .codex-imagegen generate \
--prompt "A 32x32 retro RPG pixel icon of a steel longsword with a blue grip, no text" \
--out output/icons/steel-longsword.pngRequest multiple images:
codex-imagegen generate \
--prompt "A 32x32 retro RPG pixel icon of a bronze shield with a red gem, no text" \
--out output/icons/bronze-shield.png \
--n 3Multiple outputs are written as bronze-shield-1.png, bronze-shield-2.png, and so on.
Write WebP directly by using a .webp output path:
codex-imagegen generate \
--prompt "A 32x32 retro RPG pixel icon of a bronze shield with a red gem, no text" \
--out output/icons/bronze-shield.webp \
--webp-quality 82codex-imagegen edit \
--image input/icons/iron-sword.png \
--prompt "Turn this into a fire-enchanted sword icon while keeping the same retro RPG pixel-art style, silhouette, and no text" \
--out output/icons/fire-sword.pngEdit accepts one to five --image inputs, matching the current Codex image tool limit.
Batch mode runs JSONL jobs sequentially.
mkdir -p tmp/imagegen
cat > tmp/imagegen/jobs.jsonl <<'EOF'
{"prompt":"A 32x32 retro RPG pixel icon of an iron helmet, no text","out":"iron-helmet.png"}
{"prompt":"A 32x32 retro RPG pixel icon of leather boots with tiny silver buckles, no text","out":"leather-boots.png"}
{"prompt":"Make this shield look ice-enchanted while keeping the same retro RPG pixel-art style","images":["input/icons/wooden-shield.png"],"mode":"edit","out":"ice-shield.png"}
EOF
codex-imagegen batch \
--input tmp/imagegen/jobs.jsonl \
--out-dir output/imagegen/batchEach line can be either a JSON string prompt or an object with:
prompt: required text promptout: optional output filename, resolved under--out-dirimages: optional list of image paths for edit jobsmode: optionalgenerateoredit; defaults toeditwhen images are present
--prompt-file prompt.txt: read the prompt from a file--force: allow replacing existing output files--cd PATH: base directory for resolving relative paths--auth-file PATH: read a specific Codexauth.json--codex-home PATH: read auth from another Codex home directory--model MODEL: override the Codex reasoning model used by the direct hosted image tool.--base-url URL: override the Codex backend URL for development--background auto|transparent|opaque: directbackgroundparameter.--quality auto|low|medium|high: directqualityparameter.--size auto|1024x1024|1536x1024|1024x1536: directsizeparameter.--output-format auto|png|webp: output file format. Default: infer from--out;.webpwrites WebP, everything else writes PNG.--webp-quality 1..100: WebP encoder quality. Default:85.--n COUNT: request multiple output images. The CLI runs one hosted image request per output.--dry-run: print the request shape without reading auth or contacting the backend
The CLI calls Codex directly through the enabled hosted image-generation path:
POST https://chatgpt.com/backend-api/codex/responses
The request forces the hosted image_generation tool and sends exact image options as tool parameters:
{
"model": "gpt-5.5",
"input": [
{
"type": "message",
"role": "user",
"content": [{"type": "input_text", "text": "A studio photo of a mug"}]
}
],
"tools": [
{
"type": "image_generation",
"output_format": "png",
"size": "1536x1024",
"quality": "high",
"background": "opaque"
}
],
"tool_choice": {"type": "image_generation"},
"stream": true
}Edit requests add input images to the user message:
{
"content": [
{"type": "input_text", "text": "Make it blue"},
{"type": "input_image", "image_url": "data:image/png;base64,..."}
],
"tools": [{"type": "image_generation"}]
}The accepted image preference values are:
size:auto,1024x1024square,1536x1024landscape, or1024x1536portraitquality:auto,low,medium, orhighbackground:auto,transparent, oropaque
n is handled by the CLI by running one hosted image request per output path.
For edit jobs, repeated outputs may wait for the per-minute input-image quota window before retrying; if the bucket stays full, retries back off progressively.
Codex returns PNG bytes; when the requested output is WebP, the CLI converts the PNG locally with Pillow.
codex-imagegen-cli reuses your normal Codex login. On each run it:
- reads Codex auth from
$CODEX_HOME/auth.jsonor~/.codex/auth.json - refreshes the ChatGPT access token when needed
- sends a direct Codex
/responsesrequest with an exact hostedimage_generationtool by default - streams the
image_generation_call.resultPNG bytes - writes PNG output directly, or converts locally to WebP when requested
Dry runs only print the planned request and output paths; they do not read auth or contact Codex.
This project relies on Codex's current authenticated app behavior, not a public OpenAI Images API contract.
A few things worth knowing:
- Subscription only. The built-in Codex image generation path is gated to ChatGPT auth (Plus, Pro, Business, Edu, Enterprise). It is not available on the Free plan and does not work with an
OPENAI_API_KEYsession β that key routes to the Images API instead, under separate billing. - Usage limits apply. Image generations consume your Codex account's included limits, roughly 3β5Γ faster than a comparable non-image turn. Edit jobs also consume an input-image quota; if that per-minute bucket is full, the CLI waits and retries.
- No stable API contract. Codex internals and account policies can change. The CLI may stop working or behave differently after a Codex update, and OpenAI has not documented this as a supported automation surface.
We will try to keep this project updated as long as this usage remains possible and allowed.
uv lock --check
uv sync --dev
uv run pytest
uv run ruff check .Build and validate release artifacts:
uv run python -m build
uv run python -m twine check dist/*Update a source install from the checkout:
git pull
uv tool install --reinstall -e .Uninstall the CLI:
uv tool uninstall codex-imagegen-cliReport security issues privately through GitHub Security Advisories when available. See SECURITY.md for scope and response expectations.
0.1.0 is an alpha source-install release. The CLI command shape, JSONL batch format, and Codex backend behavior may change before a stable release.
See CONTRIBUTING.md, CHANGELOG.md, and LICENSE.