Skip to main content
This page provides a ready-to-use Agent Skill: one script covers all three channels — gpt-image-2 (official), gpt-image-2-all, and gpt-image-2-vip (reverse). They all use the same OpenAI Images API; only --model differs. Drop it into the coding Agent you already use and generate images with a single prompt — just two files.

What the skill does

A single combined skill. The script auto-detects whether you pass input images to decide between text-to-image and image editing:

Text to image

Prompt only → a brand-new image, with strong text rendering and photoreal quality.

Multi-image fusion

Multiple images (up to 16) + one instruction → put person from image 1 into scene from image 2, keep the style of image 3, etc.

Inpainting

One image + a --mask + an instruction → change only the masked region (only gpt-image-2 official supports this).

Which model to choose

All three channels are called identically; they differ only in source channel, price/speed, and which params are honored. The script handles these differences automatically by --model:
Quick rule: fast & cheapgpt-image-2-all; locked size/4K & cheapgpt-image-2-vip; quality tiers, mask inpaintinggpt-image-2 (official).

Which Agents can use it

A Skill is essentially just a folder: a set of instructions for the Agent to read (SKILL.md) + a script that does the work. So any coding Agent that can read local files and run shell commands can use it — for example Codex, OpenClaw, hermes-agent, Claude Code, and more.The only requirement: the machine running the Agent (your computer or server) has Python 3 installed and network access (the script calls api.apiyi.com directly). That’s it — it is not tied to any specific Agent.

Set up in 3 steps

① Create the folder, paste the files, install the dependency

Create a skill folder with these two files (full contents in the next two sections). This skill calls via the OpenAI SDK, so install one dependency first:

② Put your key in the same folder

Write your APIYI API Key (create one in the api.apiyi.com console) into gpt-image-2/.env:
The script reads the key from this .env automatically — no extra configuration or environment variables needed.
.env holds your secret key. If you share this skill via a project repo, be sure to add .env to .gitignore and never commit it to git.

③ Hand it to your Agent

  • Agents that auto-discover skills (e.g. Claude Code): drop the whole gpt-image-2/ folder into its skills directory — personal ~/.claude/skills/, or project-level .claude/skills/ (shared via the repo).
  • Other Agents: place it per their own skill/plugin convention; or simplest of all — just tell the Agent to “read the SKILL.md in this folder and follow it”.
Once installed, you’re ready — jump to How to use it for examples.

SKILL.md

Create gpt-image-2/SKILL.md with the full content below (the description states “what it does + when to use it”, which is what the Agent uses to auto-trigger it):
name must be lowercase letters + hyphens. On Agents that support slash commands, the directory name is the command — gpt-image-2 becomes /gpt-image-2. ${CLAUDE_SKILL_DIR} is a skill-directory variable provided by Claude Code; on other Agents just use the script’s actual path.

scripts/gpt_image.py

Create gpt-image-2/scripts/gpt_image.py using the OpenAI SDK pointed at APIYI (base_url="https://api.apiyi.com/v1"):

How to switch model

Switching channel is just --model, one of three values:
To change the default channel (so you don’t pass --model every time), add a line to gpt-image-2/.env:
The script handles both base64 and url responses automatically (the reverse models’ b64_json carries a data:image;base64, prefix, which the script strips). You only need to switch your token’s billing group to image2_OSS in the APIYI console if you strictly require URL output — regular generation does not need it.

Why a single sentence generates an image

People often wonder: I never typed a command, so how did “draw a cat” produce an image? Here’s how: at startup, the Agent first reads the description from each skill’s SKILL.md (a very short piece of metadata describing “what this skill does and when to use it”). When your request matches that scenario (e.g. “draw / generate / render an image”, “fuse these images”), the Agent automatically decides to invoke the skill, reads the full SKILL.md, and runs the script — all without you remembering any command. When you don’t want the Agent to guess and want full control, use the explicit invocation below.

How to use it

Natural language (implicit trigger)

Once installed, just talk to the Agent:

Explicit invocation (more control)

  • Agents that support slash commands (e.g. Claude Code):
  • Any Agent / just tell it to run the script (most universal):

Where the generated image goes

  • When -o is a bare filename (e.g. -o cat.png), images are all saved into a gpt-image-output/ folder at the project root (created automatically), so you’ll find them right there in your project.
  • “Project root” = the first directory containing .git or .claude found by walking up from the script’s own location — so no matter which directory the Agent runs from, images land inside the project, never in a temp directory you can’t find.
  • The script prints one full absolute path per image, e.g. Image saved to /Users/you/project/gpt-image-output/cat.png.
  • By default it generates just 1 image; -n 3 produces 3 at once (max 5), with a -1, -2, -3 suffix added automatically.
  • When -o is a path with a directory (e.g. -o images/cat.png or an absolute path), it is saved at that exact path and does not go into gpt-image-output/.
  • Editing / fusion works the same way: the output is a new file and does not overwrite your original.