pi-codex-image-gen

extensionmaintained

Image generation for Pi using the ChatGPT Images 2.0 model.

by · v0.1.12 · published 3w ago

$ pi install npm:pi-codex-image-gen
downloads/mo
1.3K
stars
14
last push
1d ago
open issues
5

Signals

license: Apache-2.0testspi manifest: missinginstall size: —deps: 0peer deps: 0

Download trend

No downloads in the last 12 weeks.

README

pi-codex-image-gen

Image generation and editing for Pi using the ChatGPT Images 2.0 model via the OpenAI Codex Responses backend.

Install

pi install npm:pi-codex-image-gen

During local development from this monorepo:

pi install /path/to/pi-mono/packages/pi-codex-image-gen

For a one-off test run without installing:

pi -e /path/to/pi-mono/packages/pi-codex-image-gen

To uninstall:

pi remove npm:pi-codex-image-gen

Quick usage

In a Pi session:

> Generate a pixel-art sword icon, 32×32, with a blue blade and gold hilt

The agent will invoke codex_generate_image with your prompt, optionally include up to five local or recent conversation images for editing, stream the response from the Codex backend, and save the resulting image to disk. The model parameter controls the Codex routing model; image generation is always performed by gpt-image-2 on the backend.

Authentication

Uses your existing openai-codex login — no OPENAI_API_KEY required. If you haven't logged in yet:

> /login

Select ChatGPT Plus/Pro (Codex) and complete the OAuth flow.

Configuration

Create a JSON config file at one (or both) of these locations:

ScopePath
Global~/.pi/agent/extensions/codex-image-gen.json
Project<project-root>/.pi/extensions/codex-image-gen.json

Project config overrides global config only when project trust is active. If project trust is declined or otherwise inactive, project config is ignored and global config still applies. Example:

{
  "save": "global",
  "saveDir": "~/Pictures/generated",
  "model": "gpt-5.5"
}

Config keys

KeyTypeDefaultDescription
savestring"global"Default save mode (see below).
saveDirstringDirectory used when save=custom.
modelstring"gpt-5.5"Codex routing model. Image generation is always handled by gpt-image-2.

Environment variables

VariableDescription
PI_CODEX_IMAGE_SAVE_MODEOverrides the save config key.
PI_CODEX_IMAGE_SAVE_DIROverrides the saveDir config key (custom mode).
PI_OFFLINE=1Disables install/update telemetry.
PI_TELEMETRY=0Disables install/update telemetry.

Save modes

ModeBehavior
noneImage is returned inline but not written to disk.
projectSaves to <project>/.pi/generated-images/<session-id>/.
globalSaves to ~/.pi/agent/generated-images/<session-id>/.
customSaves to a user-specified directory (requires saveDir or env). ~ and ~/... expand to the current user's home directory.

Tool parameters

ParameterTypeRequiredDescription
promptstringThe image generation prompt.
modelstringOverride the Codex model. Defaults to config or gpt-5.5.
outputFormatstringpng (default), jpeg, or webp.
savestringOverride save mode for this call.
saveDirstringDirectory when save=custom. Relative paths resolve under CWD.
referencedImagePathsstring[]Up to five local images to edit. Relative paths resolve under CWD.
numLastImagesToIncludeintegerInclude the most recent one to five conversation images for editing. Mutually exclusive with referencedImagePaths.

How it works

  1. Resolves auth via Pi's openai-codex provider (ChatGPT session token).
  2. Sends a Codex Responses API request to the routing model (default gpt-5.5) with the image_generation tool enabled.
  3. For edits, attaches the selected local or conversation images to the request.
  4. The backend invokes gpt-image-2 to generate or edit the image.
  5. Parses the SSE stream and strictly validates the returned base64 and image format.
  6. Saves the image according to the active save mode; persistence failures produce a warning without discarding a valid inline image.
  7. Returns the image data inline plus metadata (model, format, path, revised prompt, usage).

Troubleshooting

SymptomCauseFix
"Missing openai-codex credentials"Not logged inRun /login and select ChatGPT Plus/Pro (Codex)
401 / 403 responseToken expiredRe-run /login for openai-codex
429 responseRate limitedWait and retry; the extension retries automatically with backoff
"Codex did not return an image"Backend refused the promptRephrase the prompt and try again
"save=custom requires saveDir"Missing configSet saveDir in config or PI_CODEX_IMAGE_SAVE_DIR env var

License

Apache-2.0. See LICENSE.

This package includes imagegen skill helper files derived from OpenAI Codex, including skills/imagegen/scripts/image_gen.py. Those files remain under the Apache License, Version 2.0. See NOTICE and skills/imagegen/LICENSE.txt.