@specode/pi-subscription-image
Generate and edit images in Pi using existing Codex and Grok subscription account quotas.
Package details
Install @specode/pi-subscription-image from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@specode/pi-subscription-image- Package
@specode/pi-subscription-image- Version
1.1.2- Published
- Oct 31, 2026
- Downloads
- 463/mo · 52/wk
- Author
- specode
- License
- MIT
- Types
- extension
- Size
- 80.7 KB
- Dependencies
- 0 dependencies · 3 peers
Pi manifest JSON
{
"extensions": [
"./src/index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-subscription-image
A Pi extension that generates and edits images with your OpenAI Codex or xAI Grok subscription quota via the generate_image_with_subscription tool and /img.
/subscription-image status output:
Image Generation: Codex ready; Grok ready
/img command:
/img a flat vector icon of a red panda
Supported Providers
To sign in, run /login, pick Sign in with an account (Account below), then pick the name shown in the table.
| Provider | /login option |
Capabilities | Default model | Output format |
|---|---|---|---|---|
OpenAI Codex (codex) |
Account → OpenAI Codex (legacy) |
Text-to-image, reference-image editing (up to 5 images) | gpt-5.6-sol (gpt-image-2 backend) |
png (default), jpeg, webp |
xAI Grok (grok) |
Account → xAI |
Text-to-image, 1k / 2k resolution, low / medium quality |
grok-imagine-image-2.0 |
Selected by Grok (png, jpeg, or webp) |
Provider Notes
OpenAI Codex
Sign in with a ChatGPT Plus or Pro account (Account → OpenAI Codex (legacy)). Reference-image editing accepts up to 5 local images (png, jpeg, or webp, up to 20 MB each) or recent images from the current conversation. When aspectRatio is set, it is appended to the prompt as a composition constraint.
xAI Grok
Sign in with your X Premium or SuperGrok account (Account → xAI). Grok Imagine accepts aspectRatio (defaults to 1:1), resolution (1k default or 2k), and quality (low or medium, supported on grok-imagine-image-2.0 models only) as native request parameters.
Installation
Requires Node.js >= 22.19.0.
From npm:
pi install npm:@specode/pi-subscription-image
From GitHub:
pi install git:github.com/specode/pi-subscription-image
From a local directory for development:
pi install /path/to/pi-subscription-image
Run /reload or restart Pi after installing.
Usage
Sign in through /login as described above, then ask Pi in natural language or run /img <prompt>:
- Generated images are shown inline in the conversation and saved to
~/.pi/agent/generated-images/by default. - Run
/subscription-image statusto check whether Codex and Grok credentials are available in Pi. - Multi-image requests (
nfrom1to4) run sequentially and save each image as soon as it finishes. If a later image fails or the request is cancelled, already-generated images are still returned and kept on disk.
Provider Selection
When provider is omitted or set to "auto", the extension chooses a backend in this order:
- Reference images are provided (
referencedImagePathsornumLastImagesToInclude) →codex - Active session model is under
openai-codex→codex - Active session model is under
xai→grok defaultProvideris configured → configured provider- Otherwise, the tool asks you to pass
provider="codex"orprovider="grok"(or configuredefaultProvider).
Tool Parameters (generate_image_with_subscription)
| Parameter | Description |
|---|---|
prompt |
Required. Image description or edit instruction |
provider |
auto (default), codex (aliases: openai, openai-codex), or grok (aliases: xai, grok-cli) |
model |
Model override (Codex routing model or Grok Imagine model) |
aspectRatio |
1:1, 3:4, 4:3, 9:16, 16:9, 2:3, 3:2, 9:19.5, or 19.5:9 (alias: aspect_ratio) |
n |
Number of images to generate sequentially (1–4, default 1) |
outputFormat |
Codex only: png (default), jpeg, or webp |
referencedImagePaths |
Codex only: up to 5 local image paths (png, jpeg, webp) |
numLastImagesToInclude |
Codex only: include the most recent 1–5 conversation images |
resolution |
Grok only: 1k (default) or 2k |
quality |
Grok Imagine 2.0 only: low or medium (omitted by default) |
save |
global (default, ~/.pi/agent/generated-images/), project (<cwd>/.pi/generated-images/), custom, or none |
saveDir |
Target directory when save="custom" |
Configuration
Create ~/.pi/agent/extensions/subscription-image.json (global) or .pi/extensions/subscription-image.json (trusted project override):
{
"defaultProvider": "codex",
"save": "global",
"saveDir": "~/Pictures/generated",
"providers": {
"codex": {
"routingModel": "gpt-5.6-sol",
"outputFormat": "png"
},
"grok": {
"imageModel": "grok-imagine-image-2.0",
"resolution": "1k"
}
}
}
Optional: set providers.grok.quality to "low" or "medium". Legacy top-level keys (codexRoutingModel, grokImageModel) are also accepted.
Environment Variables
| Variable | Description |
|---|---|
PI_SUBSCRIPTION_IMAGE_PROVIDER |
Default provider (codex or grok) |
PI_SUBSCRIPTION_IMAGE_SAVE_MODE |
Save mode (global, project, custom, or none; fallback: PI_IMAGE_SAVE_MODE) |
PI_SUBSCRIPTION_IMAGE_SAVE_DIR |
Directory for save="custom" (fallback: PI_IMAGE_SAVE_DIR) |
PI_SUBSCRIPTION_IMAGE_CODEX_MODEL |
Default Codex routing model |
PI_SUBSCRIPTION_IMAGE_CODEX_OUTPUT_FORMAT |
Default Codex output format (png, jpeg, or webp) |
PI_SUBSCRIPTION_IMAGE_GROK_MODEL |
Default Grok image model |
PI_SUBSCRIPTION_IMAGE_GROK_RESOLUTION |
Default Grok resolution (1k or 2k) |
PI_SUBSCRIPTION_IMAGE_GROK_QUALITY |
Default Grok quality (low or medium) |
PI_SUBSCRIPTION_IMAGE_GROK_BASE_URL |
Custom Grok API base URL (default: https://api.x.ai/v1) |
Privacy and Safety
- Credentials come only from Pi's own login (provider registry) in memory and are never written to disk by this extension.
- Requests go to
https://chatgpt.com/backend-api/codex/responsesfor Codex andhttps://api.x.ai/v1/images/generations(orPI_SUBSCRIPTION_IMAGE_GROK_BASE_URLwhen set) for Grok. - Save settings and provider parameters are validated before sending generation requests so invalid configuration does not spend quota.
- Prompts are sent as provided (with an explicit aspect-ratio line appended only on Codex when
aspectRatiois set).
Development
# Run tests
npm test
# Run typecheck, tests, extension smoke check, and package check
npm run check
# Load the extension directly in Pi without installing
pi --no-extensions --offline -e ./src/index.ts --list-models
Calling from Codemode Scripts
On Pi versions with tool outputSchema and structuredContent support, Codemode scripts can call tools.generate_image_with_subscription directly:
const result = await tools.generate_image_with_subscription({
prompt: "A red panda in watercolor",
});
for (const block of result.output) {
if (block.type === "image") image(block);
else text(block.text);
}
result has the shape { provider, model, output, generationErrors, savedPaths, saveWarnings }. Pass image blocks to image(block) rather than text(), console.log, or return so base64 image data does not hit Codemode's 16 MiB script output limit. For multiple Codex images in one script, prefer outputFormat: "webp" or "jpeg".
License
MIT. See THIRD_PARTY_NOTICES.md for adapted sources and licenses.