Imagegen
Turn an image request into saved image files through an OpenAI-compatible API. Use the bundled client so request construction, base64 decoding, data-URL handling, and file naming stay deterministic.
Workflow
- Resolve the endpoint and credentials from
OPENAI_BASE_URLandOPENAI_API_KEY. The endpoint may be either the API root or include/v1. - Resolve the model from an explicit user choice or
OPENAI_IMAGE_MODEL. If neither is available, ask for an image model rather than guessing. - Choose the branch:
- Generate when the user supplies no source image.
- Edit when the user supplies one or more source images; add
--maskonly when a mask is supplied.
- Translate the request into a concrete prompt that preserves the user's subject, composition, style, text, and constraints. Keep requested wording exact when text must appear in the image.
- Choose output settings deliberately. Use low quality for drafts when supported, raise it for final assets, and use JPEG or WebP when latency or file size matters. Request compression only with JPEG or WebP. Transparent backgrounds and exact sizes are model-dependent.
- Run
scripts/images.py generateorscripts/images.py edit. Prefer non-streamingb64_json; it yields durable local artifacts across compatibility providers. - Verify that every reported output path exists and is a non-empty image. Return the paths plus the model and material options used. Completion means every requested image has been saved or the upstream error has been reported with its response body and request ID when available.
Commands
Generate:
python scripts/images.py generate \
--prompt "A red cat sitting beside a window" \
--size 1024x1024 \
--output-dir ./generated
Edit one or more images:
python scripts/images.py edit \
--prompt "Change the cat from red to blue" \
--image ./cat.png \
--output-dir ./edited
Use repeated --image flags for composition and --mask ./mask.png for masked edits. A mask guides the edit rather than defining a pixel-exact boundary; with multiple inputs it applies to the first image. Pass provider-specific fields with --extra key=value; use JSON values for numbers, booleans, arrays, or objects.
Read references/api.md when selecting provider-specific fields, diagnosing an upstream compatibility issue, or implementing streaming. Run python scripts/images.py --help for the complete local interface.
Defaults and Boundaries
- Model precedence: explicit
--model, thenOPENAI_IMAGE_MODEL; absence is a configuration error. - Default output directory:
./generated-images; existing files are preserved by advancing the numeric suffix. - Default format:
png; the response's declared format takes precedence. - Edits use multipart uploads because that is the broadest compatible form and avoids loading source images into model context.
- Treat a returned
urlas either an HTTP URL or a data URL; the client handles both. - Keep credentials in environment variables and out of prompts, command output, and generated files.