How to Enable Local Image Generation for the gpt-image-2 Skill
Set ENABLE_GARDEN_IMAGEGEN=1 and provide a valid OPENAI_API_KEY to activate Mode A, then execute the generation scripts to create PNG files locally in the garden-gpt-image-2/image/ directory.
The gpt-image-2 skill in the ConardLi/garden-skills repository supports three distinct runtime configurations, with Mode A enabling full local image generation using OpenAI's GPT-Image-2 model. To enable local image generation for the gpt-image-2 skill, you must configure specific environment variables that signal the runtime to execute the local generation pipeline rather than delegating operations to external hosts or operating in advisory-only mode.
Understanding the Three Runtime Modes
The skill determines its operational mode at startup by inspecting environment variables in skills/gpt-image-2/scripts/check-mode.js:
- Mode A (Garden Local): Executes
generate.jsandedit.jslocally to call OpenAI's/images/generationsand/images/editsendpoints, saving outputs to the local filesystem. - Mode B (Host-Native): Delegates prompt generation to the host environment without executing local generation scripts.
- Mode C (Advisor): Functions purely as a prompt advisor without producing image files.
Only Mode A performs local image generation. When properly configured, check-mode.js outputs:
--- gpt-image-2 runtime mode ---
mode = A
recommendation = Use local generation (generate.js / edit.js)
Configuration Prerequisites
Two environment variables must be configured to enable local generation:
ENABLE_GARDEN_IMAGEGEN: Must be set to1,true,yes, oronto signal Mode A activation.OPENAI_API_KEY: Must contain a valid OpenAI API key for authenticating requests to the image generation endpoints.
Create a .env file in the repository root with these values:
ENABLE_GARDEN_IMAGEGEN=1
OPENAI_API_KEY=sk-XXXXXXXXXXXXXXXXXXXXXXXX
Step-by-Step Enablement
Follow these steps to activate and verify local image generation:
- Configure environment variables in
.envor export them directly in your shell. - Verify Mode A detection by running the mode checker.
- Prepare directory structure (
garden-gpt-image-2/prompt/andgarden-gpt-image-2/image/). - Execute generation using the provided scripts.
Verifying Your Configuration
Before generating images, confirm the skill has detected Mode A by executing skills/gpt-image-2/scripts/check-mode.js:
node skills/gpt-image-2/scripts/check-mode.js --json
Expected output for local generation mode:
{
"mode": "A",
"recommendation": "Use local generation (generate.js / edit.js)"
}
If the output shows mode: "B" or mode: "C", verify that ENABLE_GARDEN_IMAGEGEN is set to a truthy value and that the environment variables are loaded into your shell session.
Generating Images Locally
Once Mode A is active, the generation pipeline executes as follows:
- Select a template and render a prompt.
- Save the prompt to
garden-gpt-image-2/prompt/. - Invoke
generate.js, which callsPOST /images/generationson the OpenAI API. - Store the resulting PNG under
garden-gpt-image-2/image/.
Default directories are defined in skills/gpt-image-2/scripts/shared.js:
export const DEFAULT_IMAGE_DIR = "garden-gpt-image-2/image";
export const DEFAULT_PROMPT_DIR = "garden-gpt-image-2/prompt";
export const DEFAULT_MODEL = "gpt-image-2";
Generate an image from a prompt file:
node skills/gpt-image-2/scripts/generate.js \
--promptfile garden-gpt-image-2/prompt/my-poster-20260902-101500.md
Alternatively, generate from a template directly:
node skills/gpt-image-2/scripts/generate.js \
--template "ui-mockups/live-commerce-ui" \
--output garden-gpt-image-2/prompt/live-commerce-ui-$(date +%Y%m%d-%H%M%S).md
To edit existing images rather than generating from scratch, use the edit script:
node skills/gpt-image-2/scripts/edit.js \
--promptfile garden-gpt-image-2/prompt/edit-request.md
Key Implementation Files
The following source files handle local image generation in Mode A:
skills/gpt-image-2/scripts/check-mode.js: Detects runtime mode based on environment variables.skills/gpt-image-2/scripts/generate.js: Entry point for image generation; calls OpenAI API and saves PNG outputs.skills/gpt-image-2/scripts/edit.js: Handles image editing via OpenAI's edits endpoint.skills/gpt-image-2/scripts/shared.js: Exports default directory constants and model configuration.skills/gpt-image-2/SKILL.md: Contains high-level skill documentation and mode specifications.
Summary
- Set
ENABLE_GARDEN_IMAGEGEN=1to activate Mode A for local generation. - Provide
OPENAI_API_KEYto authenticate with OpenAI's image API. - Verify mode using
check-mode.jsbefore executing generation scripts. - Execute
generate.jsto create images, which saves outputs togarden-gpt-image-2/image/. - Use
edit.jsfor modifying existing images rather than generating new ones.
Frequently Asked Questions
What happens if I don't set ENABLE_GARDEN_IMAGEGEN?
Without this variable set to a truthy value, the skill defaults to Mode B (host-native delegation) or Mode C (advisor-only), neither of which produces local image files. The generation scripts will not execute locally, and no PNG files are saved to the garden-gpt-image-2/image/ directory.
Can I use local image generation without an OpenAI API key?
No. Mode A requires a valid OPENAI_API_KEY because skills/gpt-image-2/scripts/generate.js makes direct HTTP requests to https://api.openai.com/v1/images/generations. Without authentication, the API calls fail and image generation cannot complete.
Where exactly are generated images saved?
According to skills/gpt-image-2/scripts/shared.js, the default output directory is garden-gpt-image-2/image/. Each successful generation creates a PNG file in this location with a timestamp-based filename, while corresponding prompts are stored in garden-gpt-image-2/prompt/.
How do I switch from generation mode to editing mode?
Use skills/gpt-image-2/scripts/edit.js instead of generate.js. Both scripts require the same environment configuration (ENABLE_GARDEN_IMAGEGEN=1 and OPENAI_API_KEY), but edit.js calls the /images/edits endpoint to modify existing images based on provided mask and prompt files.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →