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:
Model (--model) | Channel | Price | Speed | size | quality / mask | Best for |
|---|---|---|---|---|---|---|
gpt-image-2 (default) | Official passthrough | token-based ~$0.03–0.2/img | ~100–120s | ✅ any preset | ✅ yes | quality tiers, mask inpainting, transparency control |
gpt-image-2-all | Reverse (ChatGPT line) | flat $0.03/img | fastest ~30–60s | ❌ write into prompt | ❌ | volume, speed, sizing via prompt text |
gpt-image-2-vip | Reverse (Codex line) | flat $0.03/img | ~90–150s | ✅ 30 tiers incl. 4K | ❌ | locked output size / 4K at a low price |
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 theapi.apiyi.com console) into gpt-image-2/.env:
.env automatically — no extra configuration or environment variables needed.
③ 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”.
SKILL.md
Creategpt-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):
scripts/gpt_image.py
Creategpt-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:
--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 thedescription 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:| What you say | Skill behavior |
|---|---|
| ”Draw a cinematic cat with gpt-image-2” | Default gpt-image-2, 1 png |
| ”Make a poster, fast and cheap” | Agent adds --model gpt-image-2-all |
| ”Render a 4K city night view” | Agent adds --model gpt-image-2-vip --size 3840x2160 |
| ”Put the person in person.png into scene.png” | Runs -i person.png -i scene.png, fused image |
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
-ois a bare filename (e.g.-o cat.png), images are all saved into agpt-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
.gitor.claudefound 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 3produces 3 at once (max 5), with a-1,-2,-3suffix added automatically. - When
-ois a path with a directory (e.g.-o images/cat.pngor an absolute path), it is saved at that exact path and does not go intogpt-image-output/. - Editing / fusion works the same way: the output is a new file and does not overwrite your original.
Related docs
- GPT-Image-2-All Agent Skill (reverse, fastest)
- GPT-Image-2-VIP Agent Skill (reverse, locked 4K)
- GPT-Image-2 Image Generation overview
- Nano Banana Pro Agent Skill