Codex skill for AI image generation — supports built-in tool, custom endpoints (9Router, etc), auto-reads auth.json
Generates or edits images for the current project (website assets, game assets, UI mockups, product mockups, logos, photorealistic images, infographics).
If built-in tool is available in this session → use it directly.
Best quality, no API key needed, platform-handled.
Skip all steps below if this works.
Only if built-in tool is NOT available in this session.
Read credentials from ~/.config/imagegen/auth.json:
{
"endpoint": "https://your-proxy-or-api/v1/images/generations",
"api_key": "YOUR_KEY_HERE",
"model": "cx/gpt-5.4-image"
}
Auto-detect and run:
python3 - <<'PY'
import json, os, subprocess, sys
from pathlib import Path
auth_path = Path.home() / '.config' / 'imagegen' / 'auth.json'
if not auth_path.exists():
sys.exit("[imagegen] auth.json not found. See SETUP.md for instructions.")
auth = json.loads(auth_path.read_text())
endpoint = auth.get('endpoint', '').strip()
api_key = auth.get('api_key', '').strip()
model = auth.get('model', 'gpt-image-1').strip()
if not endpoint or not api_key:
sys.exit("[imagegen] auth.json is missing 'endpoint' or 'api_key'.")
print(f"[imagegen] Using endpoint: {endpoint}")
print(f"[imagegen] Model: {model}")
PY
Full curl call:
python3 scripts/image_gen.py generate \
--prompt "<PROMPT>" \
--model "$(python3 -c "import json,pathlib; d=json.loads(pathlib.Path.home().joinpath('.config/imagegen/auth.json').read_text()); print(d.get('model','gpt-image-1'))")"\
--out output/imagegen/<filename>.png
OR via direct curl (SSE stream):
ENDPOINT=$(python3 -c "import json,pathlib; d=json.loads(pathlib.Path.home().joinpath('.config/imagegen/auth.json').read_text()); print(d['endpoint'])")
API_KEY=$(python3 -c "import json,pathlib; d=json.loads(pathlib.Path.home().joinpath('.config/imagegen/auth.json').read_text()); print(d['api_key'])")
MODEL=$(python3 -c "import json,pathlib; d=json.loads(pathlib.Path.home().joinpath('.config/imagegen/auth.json').read_text()); print(d.get('model','gpt-image-1'))")
curl -sS -N -X POST "$ENDPOINT" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-H "Accept: text/event-stream" \
-d "{\"model\":\"$MODEL\",\"prompt\":\"<PROMPT>\",\"n\":1,\"size\":\"auto\",\"quality\":\"high\",\"output_format\":\"png\"}" \
-o tmp/imagegen/response.raw
# Parse SSE and save PNG
python3 - <<'PY'
import json, base64
from pathlib import Path
raw = Path('tmp/imagegen/response.raw').read_text(errors='replace')
final = None
for block in raw.strip().split('\n\n'):
lines = block.splitlines()
ev = next((l[6:].strip() for l in lines if l.startswith('event:')), '')
data = ''.join(l[5:].strip() for l in lines if l.startswith('data:'))
if ev == 'done' and data:
final = json.loads(data)
if not final:
raise SystemExit('[imagegen] No done event in SSE response.')
out = Path('output/imagegen/result.png')
out.parent.mkdir(parents=True, exist_ok=True)
out.write_bytes(base64.b64decode(final['data'][0]['b64_json']))
print(f'[imagegen] Saved: {out} ({out.stat().st_size:,} bytes)')
PY
Environment check (strict order):
image_generation_call tool available? → use it, proceed to step 1~/.config/imagegen/auth.json exists and valid? → use curl/SDK path, proceedDecide intent: generate vs edit vs batch (see decision tree above)
Collect inputs: prompt(s), exact text (verbatim), constraints, and any input image(s)/mask(s)
If batch: write temp JSONL under tmp/imagegen/, run once, delete JSONL after
Augment prompt into a short labeled spec (structure + constraints)
Run image generation via priority order above
Inspect outputs and validate: subject, style, composition, text accuracy, constraints
Iterate with single targeted change if needed
Save final outputs to output/imagegen/ and note the final prompt used
auth.json → field model. If missing, default to gpt-image-1scripts/image_gen.py) over writing new one-off scriptsscripts/image_gen.pytmp/imagegen/ for intermediates, output/imagegen/ for final assetsReformat user prompts into a structured spec. Only make implicit details explicit; do not invent new requirements.
Template:
Use case: <taxonomy slug>
Asset type: <where the asset will be used>
Primary request: <user's main prompt>
Scene/background: <environment>
Subject: <main subject>
Style/medium: <photo/illustration/3D/etc>
Composition/framing: <wide/close/top-down; placement>
Lighting/mood: <lighting + mood>
Color palette: <palette notes>
Quality: <low/medium/high/auto>
Text (verbatim): "<exact text>"
Constraints: <must keep/must avoid>
Avoid: <negative constraints>
Generate: photorealistic-natural, product-mockup, ui-mockup, infographic-diagram, logo-brand, illustration-story, stylized-concept, historical-scene
Edit: text-localization, identity-preserve, precise-object-edit, lighting-weather, background-extraction, style-transfer, compositing, sketch-to-render
references/cli.md — how to run image_gen.py CLIreferences/image-api.md — API parameters referencereferences/prompting.md — prompting principlesreferences/sample-prompts.md — copy-paste prompt recipesSETUP.md — user setup instructions (auth.json, dependencies)