A Pi image generation extension that exposes one generate_image_with_subscription tool and uses quota from existing OpenAI Codex and xAI Grok subscription accounts.
Image extensions often expose provider-specific tools with different parameters and save behavior. This package keeps one stable tool contract, routes by the active Pi session provider, and returns every generated image inline.
- Reuses Pi's
openai-codexOAuth login for Codex image generation. - Reuses Pi's
xaisubscription login for Grok Imagine. - Provides the
generate_image_with_subscriptiontool and/imgcommand. - Automatically routes
openai-codex/*sessions to Codex andxai/*sessions to Grok. - Lets callers explicitly select
provider=codexorprovider=grokfrom other sessions. - Supports up to four sequential generations per call.
- Supports Codex reference-image editing with up to five PNG, JPEG, or WebP inputs.
- Preserves
none,project,global, andcustomsave modes. - Returns valid images inline even when optional disk persistence fails.
- Includes strict base64, MIME, timeout, retry, and response validation.
- Does not store credentials or send telemetry.
| Capability | Codex | Grok |
|---|---|---|
| Authentication | Pi openai-codex OAuth |
Pi xai subscription login |
| Text-to-image | Yes | Yes |
| Reference-image editing | Yes, up to five inputs | Not currently exposed |
| Output | PNG, JPEG, WebP | Provider-selected and detected from returned bytes |
| Aspect ratio | Prompt constraint | Native request parameter |
| Resolution | Backend-selected | 1k or 2k; default 1k |
| Quality level | Not currently exposed | low or medium; Imagine 2.0 only |
| Default model | gpt-5.6-sol routing to the currently known gpt-image-2 backend |
grok-imagine-image-2.0 |
Install from npm after the first release:
pi install npm:@specode/pi-subscription-imageTry a local checkout without installing:
pi --no-extensions --offline -e /path/to/pi-subscription-imageRestart Pi or run /reload after installation.
Use Pi's normal login flow:
/login
- Select ChatGPT Plus/Pro (Codex) for Codex.
- Select the xAI subscription login for X Premium or SuperGrok.
Check readiness without exposing credentials:
/subscription-image status
Natural language:
Generate a cinematic 16:9 image of a lunar research station at sunrise.
Direct command:
/img a flat vector icon of a red panda
The model calls generate_image_with_subscription. The public parameters are:
| Parameter | Description |
|---|---|
prompt |
Required image prompt or edit instruction |
provider |
auto, codex, or grok |
model |
Codex routing model or Grok Imagine image model |
aspectRatio |
Common aspect-ratio constraint |
n |
One to four sequential images |
outputFormat |
Codex only: png, jpeg, or webp; Grok selects the actual format |
resolution |
Grok only: 1k or 2k; default 1k |
quality |
Grok Imagine 2.0 only: low or medium; omitted by default |
save |
none, project, global, or custom |
saveDir |
Directory for save=custom |
referencedImagePaths |
Codex: up to five local images |
numLastImagesToInclude |
Codex: recent conversation images to edit |
Provider aliases are accepted:
provider=openaimaps tocodex.provider=xaimaps togrok.aspect_ratiomaps toaspectRatiobefore validation.
With provider=auto or no provider:
- Reference-image inputs select Codex.
- An
openai-codex/*session selects Codex. - An
xai/*session selects Grok. defaultProvideris used when configured.- Otherwise the tool asks for an explicit provider instead of spending quota unexpectedly.
| Mode | Location |
|---|---|
none |
Inline result only |
project |
<cwd>/.pi/generated-images/ |
global |
~/.pi/agent/generated-images/ |
custom |
saveDir or configured directory |
The default save mode is global.
Global configuration:
~/.pi/agent/extensions/subscription-image.json
Trusted project configuration:
<project>/.pi/extensions/subscription-image.json
Project values override global values only when project trust is active.
{
"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"
}
}
}Set providers.grok.quality to low or medium when needed. When omitted, the extension does not send the field to xAI. The legacy codexRoutingModel and grokImageModel keys remain supported. Global and trusted-project providers.codex and providers.grok blocks are deep-merged independently.
The truly common parameters are prompt, provider, the per-call model override, aspectRatio, n, save, and saveDir. Provider-specific capabilities remain explicit: Codex owns outputFormat and reference-image inputs; Grok owns resolution and quality. The extension does not silently rewrite or embellish prompts; only Codex receives a deterministic aspect-ratio constraint appended to the prompt.
Environment overrides:
PI_SUBSCRIPTION_IMAGE_PROVIDERPI_SUBSCRIPTION_IMAGE_SAVE_MODEPI_SUBSCRIPTION_IMAGE_SAVE_DIRPI_SUBSCRIPTION_IMAGE_CODEX_MODELPI_SUBSCRIPTION_IMAGE_CODEX_OUTPUT_FORMATPI_SUBSCRIPTION_IMAGE_GROK_MODELPI_SUBSCRIPTION_IMAGE_GROK_RESOLUTIONPI_SUBSCRIPTION_IMAGE_GROK_QUALITYPI_SUBSCRIPTION_IMAGE_GROK_BASE_URL
PI_IMAGE_SAVE_MODE and PI_IMAGE_SAVE_DIR are also accepted.
- This is an unofficial community extension.
- It reads resolved credentials through Pi's provider registry and never writes them to package-owned storage.
- Prompts and reference images are sent to the selected provider.
- Codex generation uses the ChatGPT Codex Responses backend and its built-in
image_generationtool. - Grok generation uses the xAI image generation endpoint.
- Subscription availability, quotas, regional access, and provider terms still apply.
- Backend changes can require a package update.
npm install
npm test
npm run smoke
npm run checkPushes to main and pull requests run type checking, tests, Pi loading, and package validation. The npm release workflow follows OIDC Trusted Publishing: creating a GitHub release repeats those checks and then publishes without a long-lived npm token.
MIT. See THIRD_PARTY_NOTICES.md for implementation references and attribution.