A bridge between people, agents, and image generation models.
中文
Imagen connects people and coding agents to image generation models through a shared workspace. People can browse images, adjust parameters, review requests, and manage artifacts in the TUI. Agents can use the CLI, JSON output, and bundled skills to do the same work in the same sessions.
Configure your own image endpoint, create a session, and keep working from either interface. Plans, execution records, jobs, and image artifacts are stored locally, so a request made by an agent can be inspected and continued by a person, and the other way around.
- One workspace, two interfaces. The TUI and CLI read and write the same sessions, plans, jobs, and artifacts.
- Your endpoint, your models. Profiles support OpenAI-compatible Images endpoints, Gemini native
generateContent, and other adapters. Available models and parameters come from the configured endpoint. - Explicit execution. A plan freezes the request for review. Approval and execution are separate steps; creating a plan never sends a generation request.
- Local postprocessing. Smoothing, line work, tone and color changes, periodic-frequency suppression, resizing, comparison, and contact sheets.
- Batch and background work. Local queues, independent child jobs, and an async worker.
- Agent skills. Bundled guides teach coding agents the CLI, approval rules, artifact handling, and cost and weight boundaries. They install into project or global directories for supported agents.
- Optional local upscaling. Model weights are selected and downloaded by the user, then checked against a pinned SHA-256 digest.
- English and Chinese interface text. English is the default; JSON keys, statuses, and command identifiers do not change with the language.
Processing always creates a new artifact. It never overwrites the input.
request ──► plan (review) ──► approve ──► execute ──► job + artifact
│
postprocess ◄─┴─► compare / sheet
A turn records one creation attempt. A plan records the frozen request and digest. An artifact records the image and its provenance. Sessions group turns and artifacts. None of these require the TUI: the CLI produces the same records, and the TUI renders them.
Most daily work is available in both interfaces. Keys below are TUI shortcuts.
| Task | TUI | CLI |
|---|---|---|
| Browse sessions and images | session list, preview pane, [ / ] |
session list, session show, asset show |
| Generate an image | g |
generate --input-json request.json |
| Edit an image | m |
edit --input-json request.json |
| Approve, execute, retry a plan | plan screen: a, enter, r |
plan approve, plan execute, plan retry |
| Inspect jobs | not available | job get, job wait, job fetch, job reconcile |
| Local postprocessing | t, then p for parameters |
ops, transform, compare, sheet |
| Open an image or folder | o / O |
asset open [--folder] |
| Fork, export, delete a session | f, e, x |
session fork, session export, session delete |
| Delete an image | d |
session remove-artifact, asset delete |
| Providers and models | v |
profile ..., models ..., providers |
| Cache audit and purge | c |
cache audit, cache purge |
| Batch requests | not available | batch submit, batch get, batch wait |
| Background worker | not available | worker start, worker status, worker recover |
| Agent skills | not available | skills list, skills install, skills uninstall |
| Upscaling models | not available | superres models, superres fetch, superres benchmark |
| Command reference | : palette, ? help |
imagen help, imagen schema |
| Switch interface language | l (remembered) |
--zh / --en, language |
A saved session with image preview and artifact selection.
Command help for generate.
Imagen requires Python 3.12 or later.
uv tool install "imagen-cli[tui,postprocess]"
imagen --versionThis is the supported install: uv tool puts imagen on your PATH and owns
the copy, so Imagen can update itself. Drop [tui,postprocess] if you only
need the CLI.
imagen update # is a newer release out?
imagen update --install # install it with the installer that owns this copypipx install "imagen-cli[tui,postprocess]"imagen update --install detects pipx and runs pipx upgrade imagen-cli.
uv sync --extra tui --extra postprocess
uv run imagen tuiInstall into an existing virtual environment instead:
python -m pip install '.[tui,postprocess]'
imagen tuiA checkout or a plain pip install has no standard owner: imagen update
still reports the newest release, but --install refuses and prints the
command to run instead of guessing.
tui installs Textual. postprocess installs the local image-processing dependencies. The base CLI, profiles, sessions, and provider access work without either extra.
Useful entry points:
imagen help # command index
imagen help generate # parameters for one command
imagen schema generate # JSON Schema, no network
imagen --agent help # machine-oriented reference- Configure an endpoint and a credential reference.
- Create a session.
- Generate a plan, review it, approve it, execute it.
- Inspect the job and artifact.
- Optionally postprocess the artifact or compare it with another one.
export IMAGEN_API_KEY='your-api-key'
imagen profile set local \
--provider openai \
--family images \
--base-url http://127.0.0.1:8000/v1 \
--model-default your-image-model \
--credential-ref env:IMAGEN_API_KEY
imagen models refresh --profile local
imagen session create sketchbook --output jsonThen write request.json with the returned session ID:
{
"schema_version": 1,
"operation": "generate",
"session": "ses_REPLACE_WITH_RETURNED_ID",
"profile": "local",
"prompt": "A concise cel-shaded illustration with a solid background",
"count": 1
}imagen generate --input-json request.json --output json
imagen plan approve PLAN_ID --digest PLAN_DIGEST
imagen plan execute PLAN_IDThe same flow is available in the TUI: press g, fill the form, approve the plan with a, then execute with enter.
Profiles keep an endpoint, model defaults, and a credential reference. The endpoint decides which models, operations, and parameters actually work.
imagen profile set local \
--provider openai \
--family images \
--base-url http://127.0.0.1:8000/v1 \
--model-default your-image-model \
--credential-ref env:IMAGEN_API_KEY
imagen profile list
imagen profile show local
imagen models use local --id another-modelCredential references:
env:NAMEreads an environment variable.keyring:SERVICEreads the operating-system keyring.private:NAMEreads Imagen's private store in the workspace.
To import a key file into the private store without echoing it:
imagen profile secret local --key-file ./key.txtDo not put credentials in command arguments, request files, or session exports.
Models are declared per profile:
imagen models refresh --profile local # fetch from the endpoint
imagen models add --profile local --id model-id
imagen models list --profile local
imagen models use local --id model-id # set the profile defaultIn the TUI, press v to manage profiles. Protocol, official endpoint, catalog path, and model are selection-first; choose Custom / manual input to reveal a text field. Saved custom values are preserved. Generation and edit forms let you choose a saved profile and its models.
Use gemini / generate_content for Gemini native requests, not the OpenAI Images protocol:
export GEMINI_API_KEY='your-api-key'
imagen profile set gemini \
--provider gemini \
--family generate_content \
--base-url https://generativelanguage.googleapis.com/v1beta \
--models-path /v1beta/models \
--model-default gemini-3.1-flash-image \
--credential-ref env:GEMINI_API_KEY
imagen models refresh gemini --send-credentialCustom HTTPS gateways are supported with a base URL ending in /v1beta; plain HTTP is limited to the supported loopback gateway addresses. The adapter sends x-goog-api-key and uses models/{model}:generateContent for generation and image editing. nano-banana-2 is also accepted as a gateway model alias, including provider-prefixed IDs; actual availability depends on the gateway. Native continuation context is stored privately and can be restored for later edits. Gemini does not support masks in this adapter.
--models-path is independent of the generation protocol. New CLI/TUI profiles default to /v1/models; Google's native catalog needs the explicit /v1beta/models above. A gateway may instead use /v1/models even when generation uses /v1beta. The path replaces the base URL's path on the same origin: https://gateway.example/v1beta plus /v1/models becomes https://gateway.example/v1/models. Full external URLs, query strings, and fragments are not accepted. Old profiles without this setting retain base_url + /models.
Gemini catalog parsing prefers models[].name; only when models is absent does it accept data[].id. An empty native list is kept empty. No alternate-path request or generation retry is sent automatically. A catalog entry declares a model ID, not proof that it can generate images.
Use "profile": "gemini" in the same generation/edit JSON workflow below. Model discovery sends credentials only with --send-credential; the TUI fetch button explicitly sends the selected credential to the configured endpoint.
Both operations follow the same lifecycle. generate creates an image; edit takes existing artifacts as inputs and may take a mask.
imagen generate --input-json request.json --output json
imagen edit --input-json edit-request.json --output jsonThe result is a plan with an ID and a digest. A plan does not contact the provider.
imagen plan show PLAN_ID
imagen plan approve PLAN_ID --digest PLAN_DIGEST
imagen plan execute PLAN_IDRules that matter:
- One execution sends at most one creation request.
- An approval is consumed by execution and cannot be reused.
- An unknown outcome is not retried automatically. Inspect the job first.
- An unknown cost is not recorded as zero.
plan executemay incur a provider charge.- A failed request can be retried with
plan retry, which creates a new plan; it does not reuse the old approval.
Async execution uses the local worker:
imagen generate --input-json request.json --async
imagen worker start
imagen worker status
imagen worker recover--wait waits for completion instead of returning as soon as the job is queued.
In the TUI, g generates and m edits. The plan screen supports approve (a), execute (enter), and retry (r). Approval and execution stay separate keys.
A session groups turns and artifacts. A turn is one attempt. An artifact is a saved image with provenance.
imagen session create sketchbook --output json
imagen session list
imagen session show ses_...
imagen session resume ses_...
imagen session fork ses_... --from-turn trn_... --name variant
imagen session export ses_... --to backup.zip
imagen session import backup.zip
imagen session delete ses_... --yes
imagen session remove-artifact ses_... art_...Artifacts can be inspected, opened, or deleted:
imagen asset show art_...
imagen asset open art_...
imagen asset open art_... --folder
imagen asset delete art_...
imagen session remove-artifact ses_... art_...Orphaned managed files can be reclaimed:
imagen asset gc # dry-run, lists unreferenced artifacts
imagen asset gc --plan DIGEST --yes
imagen cache audit
imagen cache purge --plan DIGEST --yesasset delete removes the artifact entity and its local file. session remove-artifact detaches the image from a session and, by default, reclaims the file when no other session references it. Soft-deleting a session frees its name for reuse; exports and imports remap identities, and exports do not include private credentials.
TUI equivalents: n creates a session, f forks the current turn, e exports, x deletes with typed confirmation, d removes the current image, o / O open the image or folder, and c audits and purges cache entries.
imagen job get job_...
imagen job wait job_... --timeout 600
imagen job fetch job_...
imagen job reconcile job_...
imagen job cancel job_...job getreads persisted facts.job waitobserves local state within a bound; it does not poll the provider.job fetchsaves inline images or safely downloads a result from a persisted response. It never regenerates.job reconcilechecks local staging and restores images.job cancelstops local observation and requests termination for locally owned work where supported.
batch submit validates every child request offline, approves and executes the batch, and creates one job per child.
imagen batch submit --input-json requests.json --concurrency 2
imagen batch get bat_...
imagen batch wait bat_... --timeout 600requests.json:
{
"concurrency": 2,
"requests": [
{
"schema_version": 1,
"operation": "generate",
"session": "ses_...",
"profile": "local",
"prompt": "first prompt",
"size": "1024x1024"
},
{
"schema_version": 1,
"operation": "generate",
"session": "ses_...",
"profile": "local",
"prompt": "second prompt",
"size": "1024x1024"
}
]
}Children succeed or fail independently. A partial failure does not re-run the whole batch; plan a new request only for the children that definitively failed. If a child's outcome is unknown, inspect that job before deciding.
Batch submission sends real requests. Obtain explicit authorization for the whole batch first.
Postprocessing is experimental. The CLI and TUI share one catalog, and every description states what the method does, what may change, and what may be lost.
Browse presets with a live preview, tune parameters, then apply. Results are saved as a new artifact.
imagen ops # catalog
imagen ops --op guided_smooth # one operator
imagen ops --preset 'Anti-AI Organic' --verbose # recipe details
imagen transform ARTIFACT_ID --preset 'Pixel Art'
imagen transform ARTIFACT_ID --op 'guided_smooth:radius=4,epsilon=0.001,strength=0.5'
imagen compare art_a art_b
imagen sheet --artifacts art_a,art_b,art_c --columns 3The catalog covers smoothing, line extraction, tone and color adjustment, periodic-frequency suppression, resizing, contact sheets, and image comparison. Some operations follow guided filtering, weighted least squares, or Local Laplacian methods; variants and approximations are labeled.
Limits:
- Smoothing may remove fine lines.
- Sharpening may amplify noise.
- Frequency suppression may delete intentional halftone patterns.
- Difference metrics do not replace visual inspection.
- Operations have not completed image-quality and preference evaluation across illustration, photography, and other domains.
TUI: t opens the transform studio; p edits parameters; enter applies. Applying saves a new artifact and leaves the source untouched.
List local models and their licenses without downloading anything:
imagen superres modelsAfter choosing a model and reviewing its source and weight license:
imagen superres fetch --model realesrgan-x4plus --accept
imagen superres benchmark --artifact ARTIFACT_ID --model realesrgan-x4plusInstall the optional runtime explicitly (the first command only previews):
imagen runtime install --backend cpu
imagen runtime install --backend cpu --acceptThe command targets the running ImagenCli virtual environment, never system Python.
Choose cuda or openvino explicitly for those distributions; conflicting ONNX runtime
packages are refused, not silently removed. GPU drivers are not installed. Restart
ImagenCli after installation. In a uv-managed source checkout, keep --extra ai-onnx
(or the selected backend extra) in subsequent uv run/uv sync commands.
The TUI command palette exposes the same backend and acceptance choices.
Same-size restoration also uses the existing superres operation:
imagen superres fetch --model film-degrainer --accept
imagen transform ARTIFACT_ID --op superres:model=film-degrainer
imagen superres fetch --model dejpg-srformer-light --accept
imagen transform ARTIFACT_ID --op superres:model=dejpg-srformer-lightFilm-Degrainer by tika is listed as CC0-1.0. DeJPG_SRFormer_light by Helaman is
CC BY 4.0: retain attribution and indicate changes. These are community ONNX
conversions by notaneimu, not official exports. Sources and license notes appear
in imagen superres models; neither model enlarges the image or guarantees improvement.
Downloaded weights are staged, checked against a pinned SHA-256 digest, and only then published into the weights directory. Failed or mismatched downloads leave no usable weight behind.
Imagen does not silently install the upscaling runtime or weights. A source-code license does not grant permission to use model weights. Reconstructed texture is not guaranteed to have existed in the original image.
Imagen ships skills that teach coding agents when to use it, how to discover commands and schemas, how to follow the plan and approval lifecycle, how to handle unknown outcomes, and how to respect cost, credential, and weight-download boundaries.
imagen skills list
imagen skills install # asks which agents, in a terminal
imagen skills install --target universal # the shared .agents/skills directory
imagen skills install --target claude-code --target codex
imagen skills install --scope global --target claude-code
imagen skills uninstall --target codex- Default scope is the current project;
--scope globalinstalls into user directories. - Without
--target, skills go touniversal— the shared.agents/skillsdirectory that most agents read. Add more agents with--target, which may be repeated;--target allselects every target in the bundled compatibility table. - In a terminal without
--target, Imagen opens a checklist: arrows move, space selects,aselects all, enter confirms,qcancels. The shared directory and any agent directory already present in the project start ticked. Without a terminal — or with--no-interactive— the command installs into the default target and never prompts. - Project-only agents are reported when global installation is requested.
- Installation writes a managed manifest (
.imagen-install.json). Uninstall refuses unmanaged directories and symlinked paths. A locally modified managed skill needs--force --yes.
The bundled skills are imagen, imagen-assets, and imagen-batch.
--agent returns one JSON envelope; --output json does the same; --output jsonl emits events.
{
"schema_version": 1,
"ok": false,
"status": "approval_required",
"data": {},
"error": {
"type": "approval_required",
"message": "...",
"retryable": false,
"accepted_maybe": false,
"next_actions": []
}
}JSON keys, status names, and identifiers are identical in English and Chinese. Only human-readable message text follows the interface language.
Exit codes:
| Code | Meaning |
|---|---|
| 0 | succeeded, accepted, approved, or planned |
| 2 | validation error or unsupported capability |
| 3 | authentication or permission error |
| 4 | not found |
| 5 | conflict |
| 6 | wait timeout, unknown outcome, or approval required |
| 7 | failed, save failed, or canceled |
| 8 | safety refusal |
| 9 | partial success |
imagen schema COMMAND returns the input, data, and event schemas. imagen help --agent returns the command index and the calling rules.
Sessions, plans, jobs, managed images, cache, and private credentials live in the workspace, by default under the user data directory. Use --workspace PATH to point commands at another workspace.
- Generation and editing send the prompt and required inputs to the endpoint you configured. Its retention, logging, and billing policies apply.
- Session exports exclude private credentials.
- Provider errors are reduced to safe categories; raw response bodies are never echoed into human output.
- Imagen does not retry unknown creation outcomes automatically.
- Imagen does not overwrite the source artifact during postprocessing.
- Imagen does not download model weights without explicit acceptance.
English is the default for help, human output, errors, and the TUI.
imagen --zh help # Chinese for one command
imagen --en help # force English
export IMAGEN_LANG=zh-CN # current shell only
imagen language zh-CN # save as the default
imagen language # show the saved default
imagen tui--zh and --en are shortcuts; --lang en|zh-CN is the explicit form. A language flag takes precedence over IMAGEN_LANG, and only one language selector may be used per command.
imagen language [en|zh-CN] writes the default to the platform config directory (config.json under the Imagen user config path, readable only by you). The TUI's l key saves the same preference, so the choice survives restarts. Precedence is: command-line flag, then IMAGEN_LANG, then the saved default, then English.
approval_required. Review the plan, then run plan approve with its digest, followed by plan execute.
unknown outcome. Do not rerun the request. Use job get and, when a response was persisted, job fetch or job reconcile.
The model is missing. Run models refresh --profile NAME, or declare it with models add --profile NAME --id MODEL.
The endpoint rejects edit or a parameter. Capability depends on the provider and model. Check providers, the model catalog, and the endpoint documentation.
The TUI preview is unavailable. Image preview needs a truecolor terminal. The artifact still opens with o or imagen asset open.
A skill cannot be uninstalled. The directory is unmanaged, symlinked, or was modified after installation. Inspect the reported path first. Locally modified managed skills need --force --yes; unmanaged directories are never taken over.
Upscaling fails before inference. The runtime or weights are missing. Run superres models, then superres fetch --model NAME --accept after reviewing the license.
- Provider execution: complete remote asynchronous job handling alongside the local queue and worker.
- Image quality: expand evaluation across illustration, photography, and other domains, including visual comparison and user preference. Postprocessing stays experimental until this is complete.
- Platform support: verify Windows on physical hardware and improve processing resource controls on Windows and macOS. Current size, buffer, and timeout checks are not a complete sandbox; Linux address-space limits do not cap RSS or GPU memory.
- Language support: add more interface languages. English is the default; Chinese is available through
--lang zh-CNorIMAGEN_LANG=zh-CN. - Parity: bring batch, worker, skills, and upscaling management into the TUI.
uv sync --group dev --extra tui --extra postprocess
uv run pytest
uv run ruff check .
uv run mypy srcThe default test suite is offline. Live provider tests are marked live and require explicit authorization and credentials; they are not part of normal development.
Source layout:
| Path | Responsibility |
|---|---|
src/imagen_cli/cli |
entrypoint, registry, renderers, TUI |
src/imagen_cli/application |
planning, execution, artifacts, sessions, postprocessing, skills |
src/imagen_cli/domain |
contracts, identifiers, errors |
src/imagen_cli/providers |
endpoint adapters |
src/imagen_cli/execution |
queues, workers, configured execution |
src/imagen_cli/storage |
SQLite, artifacts, private state, workspace safety |
Small, focused changes are preferred. Add tests for behavior changes, keep provider requests behind the plan and approval boundary, and do not add live or paid provider tests without explicit authorization.
Imagen source code is available under the MIT License. Third-party dependencies, provider services, and model weights are covered by their own terms.






