# Codex Gpt Image 2 Generation

> Generate, persist, and display text-to-image assets with Tuzi's fixed gpt-image-2 model by automatically reading the active model provider's experimental_bearer_token from Codex config.toml. Use when the user invokes this Skill or asks for a business image, marketing visual, product illustration, poster, social image, transparent asset, or other image through their Codex-configured Tuzi account without manually entering a Key. Run the bundled script so the result is a real local file instead of relying on Codex's hosted image attachment handoff.

- Skill: `jerry-george-liang/codex-gpt-image-2-generation` (Agent Skill, multi-file: 5 files)
- Install (CLI): `npx skillmds@latest add jerry-george-liang/codex-gpt-image-2-generation`
- Raw SKILL.md: https://api.skillmd.com/api/skills/jerry-george-liang/codex-gpt-image-2-generation/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Marketing & Growth
- Author: Jerry-George-Liang (https://skillmd.com/u/jerry-george-liang)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/jerry-george-liang/codex-gpt-image-2-generation

---


# Codex GPT Image 2 Generation

Run the bundled script to generate and save text-to-image assets with the fixed `gpt-image-2` model.

## Execution contract

- For a request using this Skill, run `scripts/generate_business_image.py`. Do not substitute Codex's built-in or hosted `image_gen` call.
- Read the Key automatically from the active provider in Codex `config.toml`. Do not ask the user to paste a Key and do not accept a Key, model, or base URL as an argument.
- When the user supplies only a prompt, pass only `--prompt`; let the script use its defaults.
- Do not automatically retry a failed or timed-out generation because the first request may still consume quota.
- Treat the task as complete only after at least one real local image file exists and is presented to the user.

## Security contract

- Read `$CODEX_HOME/config.toml`, defaulting to `~/.codex/config.toml`. Select the provider named by top-level `model_provider`, require its `base_url` to be `https://api.tu-zi.com/coding`, and use only its `experimental_bearer_token` value.
- Do not fall back to `auth.json` or another provider's token.
- Never display, log, return, copy, or rewrite the API Key.
- Never accept a Key, model name, or base URL as a command-line argument.
- Never add a credential to this Skill, a project, a ZIP, an image prompt, or a generated file.
- Stop if Codex uses another authentication format or the configured Key cannot access `gpt-image-2`.

Read [references/runtime.md](references/runtime.md) when diagnosing credentials, API compatibility, or another user's installation. Read [references/prompting.md](references/prompting.md) when the business-image request needs prompt structure or visual constraints.

## Workflow

1. Preserve the user's business facts, brand wording, required text, composition, dimensions, and exclusions. Do not invent a logo, certification, discount, price, product claim, or contact detail.
2. If the user did not choose a layout, omit layout arguments. The script defaults to `size=auto`, one image, `quality=auto`, PNG, and automatic background.
3. Run the script with the prompt and only the options the user actually requested. Pass the prompt as one safely quoted argument; never interpolate it into executable shell syntax.
4. Parse the JSON result. Require exit code 0 and a nonempty `saved_files` array. Confirm every returned path exists and is nonempty.
5. Use the non-sensitive `timings` object to report performance only when useful. `api_request_ms` covers the synchronous API wait, `image_download_ms` covers returned image URL downloads, `save_images_ms` covers download/decoding plus local writes, and `total_ms` covers the complete script run. Do not infer billing from these values.
6. Present each image using its absolute local path. In Codex Desktop, include both an inline image and a download link:

   ```markdown
   ![生成图片](/absolute/path/to/image.png)
   [下载原图](/absolute/path/to/image.png)
   ```

7. Do not claim that an attachment was returned unless it is visibly rendered. If inline rendering fails, still provide the verified absolute file link.
8. Report API errors concisely without exposing credentials or automatically retrying.

## Credential check

Check whether the current Codex configuration contains a usable Key without making an API request:

```bash
python3 <skill-directory>/scripts/generate_business_image.py --status
```

The status result shows only whether a credential exists, which config file was checked, and which provider was selected. It never shows the Key.

## Generate an image

Normal prompt-only flow:

```bash
python3 <skill-directory>/scripts/generate_business_image.py \
  --prompt "面向企业客户的云服务宣传主视觉，深蓝科技风，留出标题区域"
```

Add rendering options only when requested:

```bash
python3 <skill-directory>/scripts/generate_business_image.py \
  --prompt "面向企业客户的云服务宣传主视觉，深蓝科技风，留出标题区域" \
  --aspect-ratio 16:9 \
  --quality auto \
  --output-format png \
  --output-dir /absolute/path/to/generated-images
```

Optional arguments:

```text
--size auto|1K|1024x1024|1536x1024|1024x1536
--aspect-ratio 1:1|16:9|9:16|3:2|2:3
--quality auto|low|medium|high
--output-format png|jpeg|webp
--background auto|transparent|opaque
--count 1..10
--output-dir /absolute/path
```

Do not pass both `--size` and `--aspect-ratio`. Transparent backgrounds require PNG or WebP.

Without `--output-dir`, files are saved under `$CODEX_HOME/generated_images/codex-gpt-image-2-generation`, defaulting to `~/.codex/generated_images/codex-gpt-image-2-generation`.

## Boundaries

- Support text-to-image generation only. Do not claim to edit a reference image.
- Keep the model fixed to `gpt-image-2`, even if the user asks this Skill to switch models. Use a different Skill for other models.
- Keep the API endpoint fixed to the Tuzi Codex-group synchronous image endpoint at `https://api.tu-zi.com/coding/v1/images/generations`.
- A successful Codex text-model session does not prove the same Key has an available `gpt-image-2` channel. Report the upstream error if access is unavailable.
- Download returned HTTPS URLs or decode returned Base64 images and detect the real image format from the file content.
- Treat requested size and aspect ratio as targets rather than guaranteed output dimensions. Inspect the saved file when exact dimensions matter, then crop or resize in a separate step.

