GPT-image-2 Image Generation and Editing Shiyun API: Integrating ShiyunApi Text-to-Image and Image Editing in Agents

Introduction

When creating posters, avatars, or product images in environments like Cursor or Claude Code, the common practice is to manually write curl scripts to call third-party image APIs, and then persist the returned URL or base64 data to disk. Given the numerous interface fields and the different endpoints for text-to-image generation versus editing, agents often select the wrong workflow between “text-only input” and “modifying an existing image.” This article introduces the SkillHub community Skill “GPT-image-2 Image Generation & Editing ShiyunAPI” (Coordinate: @user_cfdd25ec/gpt-image-2-shiyunapi, version 1.0.0). It encapsulates GPT-image-2 on the ShiyunApi platform into scripts and instructions executable by agents, unifying both text-to-image generation and image editing capabilities.

What is this

In one sentence: It utilizes GPT-image-2 to perform text-to-image generation, as well as editing, inpainting, and multi-image composition based on input images, with the underlying model service provided by ShiyunApi.

Maintenance & Distribution: Community sourced. Published by user_cfdd25ec. Categorized under design-media on SkillHub, with the tag requires_api_key=true. SkillHub Page: https://www.skillhub.cn/skills/user_cfdd25ec/gpt-image-2-shiyunapi.

Core Functions

The Skill defines two types of tasks and corresponding HTTP interfaces in SKILL.md:

  1. Text-to-Image Generation: POST https://shiyunapi.com/v1/images/generations. Generates new images from text prompts. The Agent runs scripts/generate_image.py.
  2. Image Editing: POST https://shiyunapi.com/v1/images/edits. Modifies, changes backgrounds, adjusts styles, or composes images based on one or more png / jpg / jpeg / webp inputs. Runs scripts/edit_image.py.

Decision Rules: Briefly, if the user only provides text and the goal is to “generate/draw a new image,” use text-to-image generation. If the user provides or references an existing image, or requests to “modify this image,” use editing. Video generation, purely local offline photo editing, and non-ShiyunApi providers are out of the scope of this Skill (unless the user explicitly requests switching to ShiyunApi).

Optional Parameters: Include model (default gpt-image-2), quantity n (1–10), size size, quality quality, and output format format. Editing scenarios also accept mask (where transparent areas indicate parts to edit), background, moderation, etc. The script saves URL or base64 responses as images and writes out response.json and metadata.json when necessary to facilitate troubleshooting.

Installation and Activation

Install via SkillHub

The official page suggests installing this Skill according to https://skillhub.cn/install/skillhub.md. If the skillhub CLI is already available on your machine, you can install the package to the current Agent’s skills directory (the --dir flag is mandatory during installation; otherwise, it defaults to ./skills/ and may not be recognized):

skillhub install @user_cfdd25ec/gpt-image-2-shiyunapi --dir ~/.cursor/skills/

Other common paths (from SkillHub installation docs): ~/.claude/skills/ for Claude Code; ~/.codex/skills/ or .agents/skills/ under the project directory for Codex. Replace --dir based on the client you are actually using.

If the CLI is not installed, you can run the following first:

curl -fsSL https://skillhub-1388575217.cos.ap-guangzhou.myqcloud.com/install/install.sh | bash

API Key

A Shiyun API Key is required before making calls. The Skill prioritizes reading the environment variable SHIYUN_API_KEY. When a user provides a Key during conversation, it should be persisted via stdin to avoid appearing in the command line or logs:

python "scripts/save_api_key.py" --api-key-stdin

Key creation address: https://shiyunapi.com/console/token. Do not write the Key into Skill documentation, memory, or project files.

Typical Usage

The following examples are taken from the Skill’s references/examples.md; please replace paths with actual directories in your workspace. Scripts need to be executed within the Skill installation directory (or use the full path to generate_image.py / edit_image.py).

Text-to-Image (Avatar): Generate a 1024×1024 PNG image.

python "scripts/generate_image.py" \
  --prompt "An orange cat avatar wearing round-framed glasses, clean background, soft lighting, digital illustration style" \
  --size 1024x1024 \
  --format png \
  --output-dir "./output"

Text-to-Image (Product Poster):

python "scripts/generate_image.py" \
  --prompt "High-end Bluetooth earphone product poster, dark blue gradient background, tech-style lighting effects, central product display, space reserved for Chinese title" \
  --size 1024x1024 \
  --quality auto \
  --format png \
  --output-dir "./output"

Editing: Change Background (Requires an input image first):

python "scripts/edit_image.py" \
  --image "./input/product.png" \
  --prompt "Keep the product subject and details, change the background to a high-end gray gradient photography studio, add soft shadows" \
  --model gpt-image-2 \
  --output-dir "./output"

Editing: Local Repainting with Mask:

python "scripts/edit_image.py" \
  --image "./input/room.png" \
  --mask "./input/window_mask.png" \
  --prompt "Only modify the transparent mask area, change the scenery outside the window to a sunny seascape, keep other interior areas unchanged" \
  --model gpt-image-2 \
  --output-dir "./output"

Editing: Multi-image Composition (Multiple --image flags):

python "scripts/edit_image.py" \
  --image "./input/person.png" \
  --image "./input/bag.png" \
  --prompt "Naturally composite the person and the bag into a fashion street snap ad image, keep the person's face unchanged, place the bag on the person's right hand" \
  --model gpt-image-2 \
  --size 1024x1536 \
  --output-dir "./output"

Upon success, the script outputs JSON similar to {"code": 0, "files": [".../image_1.png"], "msg": "图片生成或编辑成功"}. If the response structure cannot be parsed as an image, you may receive code: 202 and a saved response.json.

In Agent conversations, you can also directly describe your needs (generate poster, change background, inpaint, etc.). The Skill’s trigger keywords include “文生图” (Text-to-Image), “图片编辑” (Image Editing), “ShiyunApi”, “gpt-image-2”, etc., allowing the Agent to select scripts and parameters according to SKILL.md.

Scenarios and Notes

Who it is for: Developers or creators who need to accomplish GPT-image-2 text-to-image generation or editing based on reference images within coding assistants, and are willing to use the Shiyun API pay-as-you-go billing system.

Precautions:

  • Depends on network and a valid API Key; if quota is insufficient, recharge at https://shiyunapi.com/console/topup.
  • The text-to-image documentation mixes model and modal fields. The Skill defaults to model. In case of anomalies, check references/api_docs.md or use --model-field auto (retries may consume quota).
  • For editing single images, recommend size < 25MB; mask PNGs < 4MB and match the dimensions of the first image; 413 errors are usually due to file size being too large.
  • Interface documentation may not perfectly match actual response structures; the Skill notes that actual returns should be treated as the standard.

Conclusion

“GPT-image-2 Image Generation & Editing ShiyunAPI” consolidates ShiyunApi’s text-to-image and editing interfaces, parameter conventions, and troubleshooting guides into a unified Agent Skill, reducing manual request writing and workflow misjudgment. See SkillHub for installation and details: https://www.skillhub.cn/skills/user_cfdd25ec/gpt-image-2-shiyunapi; API Distribution Address: https://api.skillhub.cn/user_cfdd25ec/gpt-image-2-shiyunapi.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye