Install
$ agentstack add skill-jovijovi-skills-openai-gpt-image-api ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ● Network access Used
- ● Filesystem access Used
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
OpenAI GPT Image API
Use this skill when the user asks how to call OpenAI's GPT image models directly, especially gpt-image-2.
Key rule
If the user wants to explicitly select gpt-image-2, use the Image API:
POST /v1/images/generations- SDK:
client.images.generate(...)
Do not recommend the Responses API image tool for explicit model pinning. The docs note that the Responses API image_generation tool uses its own GPT Image model selection, so it is better for conversational workflows than for guaranteed direct selection of gpt-image-2.
When to use which API
Use Image API when:
- Single-turn text-to-image generation
- Single-turn image edit / inpainting
- The caller wants to explicitly set
model="gpt-image-2" - The caller wants direct control of size / quality / format / compression
Use Responses API when:
- Multi-turn image editing inside a conversation
- You want the main model to decide when to generate vs edit
- You want to pass image File IDs in conversational context
Core model facts
From OpenAI docs:
- Latest GPT image model:
gpt-image-2 - Snapshot example:
gpt-image-2-2026-04-21 - Image endpoints include:
/v1/images/generations/v1/images/edits- Responses tool type:
image_generation - Organization verification may be required before using GPT Image models
Quick Start CLI script
This skill now includes a runnable Python CLI script:
scripts/gpt_image_2_cli.py
Use it for either generation or editing.
Generate an image
python ~/.hermes/skills/mlops/openai-gpt-image-api/scripts/gpt_image_2_cli.py generate \
--api-key YOUR_OPENAI_API_KEY \
--prompt "A realistic photo of a small kitten sitting by a window, warm morning light" \
--output kitten.png
Edit an image
python ~/.hermes/skills/mlops/openai-gpt-image-api/scripts/gpt_image_2_cli.py edit \
--api-key YOUR_OPENAI_API_KEY \
--prompt "Turn this into a cinematic watercolor illustration" \
--image input.png \
--output edited.png
Inpaint with a mask
python ~/.hermes/skills/mlops/openai-gpt-image-api/scripts/gpt_image_2_cli.py edit \
--api-key YOUR_OPENAI_API_KEY \
--prompt "Replace the masked area with a red ceramic mug" \
--image desk.png \
--mask mask.png \
--output inpainted.png
The script accepts --api-key directly and, if omitted, prompts securely for the key at runtime.
Minimal Python example
from openai import OpenAI
import base64
client = OpenAI()
result = client.images.generate(
model="gpt-image-2",
prompt="A realistic photo of a small kitten sitting by a window, warm morning light",
)
with open("kitten.png", "wb") as f:
f.write(base64.b64decode(result.data[0].b64_json))
Minimal Node.js example
import OpenAI from "openai";
import fs from "fs";
const openai = new OpenAI();
const result = await openai.images.generate({
model: "gpt-image-2",
prompt: "A realistic photo of a small kitten sitting by a window, warm morning light"
});
fs.writeFileSync("kitten.png", Buffer.from(result.data[0].b64_json, "base64"));
Minimal curl example
curl -X POST "https://api.openai.com/v1/images/generations" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A realistic photo of a small kitten sitting by a window, warm morning light"
}' | jq -r '.data[0].b64_json' | base64 --decode > kitten.png
Output handling
GPT Image responses from the Image API return base64 image data in:
result.data[0].b64_json
Decode it before saving.
Useful parameters
result = client.images.generate(
model="gpt-image-2",
prompt="A ceramic teacup on a wooden table, studio product photo",
size="1536x1024",
quality="high",
output_format="jpeg",
output_compression=80,
background="auto",
)
Common parameters:
modelpromptsizequalityoutput_format=png|jpeg|webpoutput_compression= 0..100 for jpeg/webpbackground=opaque|autonfor multiple images
gpt-image-2 size constraints
Docs note:
- Max edge length:
<= 3840 - Both dimensions must be multiples of
16 - Long edge / short edge ratio must not exceed
3:1 - Total pixels must be between
655,360and8,294,400
Common sizes:
1024x10241536x10241024x15362048x20482048x11523840x21602160x3840auto
Square images are typically fastest.
Quality guidance
low: drafts, quick iterations, thumbnailsmedium: balanced default for many caseshigh: final assetsauto: let model choose
Important limitations / pitfalls
Transparent background
gpt-image-2 does not currently support background="transparent". Use:
background="opaque", orbackground="auto"
Latency
Complex prompts can take up to ~2 minutes.
Text rendering and layout
Still improved but not perfect:
- precise text placement can fail
- strict layout-sensitive compositions may drift
- visual consistency across repeated character generations may vary
Responses API caveat
In Responses API, this is valid:
response = client.responses.create(
model="gpt-5.4",
input="Generate an image of a gray tabby cat hugging an otter",
tools=[{"type": "image_generation"}],
)
But use this for conversational workflows, not when the user specifically asks to directly call gpt-image-2.
Verification checklist
Before finalizing advice, confirm:
- If the user wants explicit
gpt-image-2selection, recommend Image API. - Mention base64 decoding.
- Mention transparent background is unsupported on
gpt-image-2. - Mention size constraints if discussing custom resolutions.
- Mention org verification may be required if access issues arise.
- If the user wants runnable code, prefer the bundled
scripts/gpt_image_2_cli.pyscript and show the exact command.
Bundled script behavior
scripts/gpt_image_2_cli.py supports:
generatesubcommand for text-to-imageeditsubcommand for image editing or reference-based generation- multiple
--imageinputs for edit mode - optional
--maskfor inpainting --size,--quality,--output-format,--output-compression,--background, and--n--outputfor a single file or--output-dirfor multiple outputs- default model
gpt-image-2
If --output is omitted, the script writes numbered files into the current directory.
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: jovijovi
- Source: jovijovi/skills
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.