# How to Enable Local Image Generation for the gpt-image-2 Skill

> Enable local image generation for gpt-image-2 skill by setting ENABLE_GARDEN_IMAGEGEN=1 and providing your OPENAI_API_KEY. Learn how to create PNG files locally.

- Repository: [ConardLi/garden-skills](https://github.com/ConardLi/garden-skills)
- Tags: how-to-guide
- Published: 2026-09-02

---

**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`](https://github.com/ConardLi/garden-skills/blob/main/skills/gpt-image-2/scripts/check-mode.js):

- **Mode A (Garden Local):** Executes [`generate.js`](https://github.com/ConardLi/garden-skills/blob/main/generate.js) and [`edit.js`](https://github.com/ConardLi/garden-skills/blob/main/edit.js) locally to call OpenAI's `/images/generations` and `/images/edits` endpoints, 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`](https://github.com/ConardLi/garden-skills/blob/main/check-mode.js) outputs:

```text
--- 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 to `1`, `true`, `yes`, or `on` to 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:

```dotenv
ENABLE_GARDEN_IMAGEGEN=1
OPENAI_API_KEY=sk-XXXXXXXXXXXXXXXXXXXXXXXX

```

## Step-by-Step Enablement

Follow these steps to activate and verify local image generation:

1. **Configure environment variables** in `.env` or export them directly in your shell.
2. **Verify Mode A detection** by running the mode checker.
3. **Prepare directory structure** (`garden-gpt-image-2/prompt/` and `garden-gpt-image-2/image/`).
4. **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`](https://github.com/ConardLi/garden-skills/blob/main/skills/gpt-image-2/scripts/check-mode.js):

```bash
node skills/gpt-image-2/scripts/check-mode.js --json

```

Expected output for local generation mode:

```json
{
  "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:

1. **Select a template** and render a prompt.
2. **Save the prompt** to `garden-gpt-image-2/prompt/`.
3. **Invoke [`generate.js`](https://github.com/ConardLi/garden-skills/blob/main/generate.js)**, which calls `POST /images/generations` on the OpenAI API.
4. **Store the resulting PNG** under `garden-gpt-image-2/image/`.

Default directories are defined in [`skills/gpt-image-2/scripts/shared.js`](https://github.com/ConardLi/garden-skills/blob/main/skills/gpt-image-2/scripts/shared.js):

```javascript
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:

```bash
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:

```bash
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:

```bash
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`](https://github.com/ConardLi/garden-skills/blob/main/skills/gpt-image-2/scripts/check-mode.js):** Detects runtime mode based on environment variables.
- **[`skills/gpt-image-2/scripts/generate.js`](https://github.com/ConardLi/garden-skills/blob/main/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`](https://github.com/ConardLi/garden-skills/blob/main/skills/gpt-image-2/scripts/edit.js):** Handles image editing via OpenAI's edits endpoint.
- **[`skills/gpt-image-2/scripts/shared.js`](https://github.com/ConardLi/garden-skills/blob/main/skills/gpt-image-2/scripts/shared.js):** Exports default directory constants and model configuration.
- **[`skills/gpt-image-2/SKILL.md`](https://github.com/ConardLi/garden-skills/blob/main/skills/gpt-image-2/SKILL.md):** Contains high-level skill documentation and mode specifications.

## Summary

- **Set `ENABLE_GARDEN_IMAGEGEN=1`** to activate Mode A for local generation.
- **Provide `OPENAI_API_KEY`** to authenticate with OpenAI's image API.
- **Verify mode** using [`check-mode.js`](https://github.com/ConardLi/garden-skills/blob/main/check-mode.js) before executing generation scripts.
- **Execute [`generate.js`](https://github.com/ConardLi/garden-skills/blob/main/generate.js)** to create images, which saves outputs to `garden-gpt-image-2/image/`.
- **Use [`edit.js`](https://github.com/ConardLi/garden-skills/blob/main/edit.js)** for 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`](https://github.com/ConardLi/garden-skills/blob/main/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`](https://github.com/ConardLi/garden-skills/blob/main/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`](https://github.com/ConardLi/garden-skills/blob/main/skills/gpt-image-2/scripts/edit.js) instead of [`generate.js`](https://github.com/ConardLi/garden-skills/blob/main/generate.js). Both scripts require the same environment configuration (`ENABLE_GARDEN_IMAGEGEN=1` and `OPENAI_API_KEY`), but [`edit.js`](https://github.com/ConardLi/garden-skills/blob/main/edit.js) calls the `/images/edits` endpoint to modify existing images based on provided mask and prompt files.