An image generation skill implemented based on the ChatGPT latest image generation gpt-image-2-all model on the API易 platform. It can help users generate images through natural language, accessed via API易's domestic proxy service, and supports both Node.js and Python runtime environments. gpt-image-2-all is a GPT image generation official reverse model launched on the API易 platform, with highly competitive per-use pricing of $0.03/image, generating images in about 60 to 300 seconds, supporting text-to-image/single-image editing/multi-image fusion/natural language image modification, with high text fidelity, few content restrictions, and native support for Chinese prompts.
Usage Guide
Follow these steps:
Step 1: Analyze requirements and extract parameters
- Clarify intent: Distinguish whether the user needs [text-to-image] (generate a new image), [image-to-image] (edit/modify an existing image), or [multi-image fusion].
- Prompt analysis:
- Use the user's original complete input: Use the user's original complete problem requirement description (original text) directly as the
-pmain body of the prompt, avoiding rewriting, summarizing, or secondary creation on your own to prevent loss of details. - Confirm first when supplementation is needed: If the information is insufficient (for example, missing style, number of subjects, camera language, scene details, text content, prohibited elements, etc.), first ask the user to confirm; after the user confirms, then append the supplementary contentin an "append" mannerto the end of the original prompt.
- Example:
- User input: "Help me generate an image of a cat, the style should be a bit cute."
- Positive example explanation: directly use the user input as the prompt:
-p "帮我生成一张猫的图片,风格要可爱一点。" - Negative example explanation: arbitrarily rewriting it as "generate an image of a cute-style cat" will lose the details and tone of the user's original input.
- If details need to be supplemented (for example, color, background, etc.), first ask and confirm: "What color do you want the cat to be? Any requirements for the background?" After the user answers, then append to the prompt:
-p "帮我生成一张猫的图片,风格要可爱一点。猫是橘色的,背景是草地。"
- Use the user's original complete input: Use the user's original complete problem requirement description (original text) directly as the
- Organize key parameters:
- Prompt (required): The final prompt after prompt analysis (default = the user's original complete and consistent input; supplementary information is appended only after user confirmation).
- Filename (optional): Output image filename/path (must include a random file identifier to avoid duplication). If not provided, the script will automatically generate a filename with a timestamp. It is recommended to generate a reasonable filename based on the content (for example,
cat_in_garden.png), avoiding generic names. - Size/Aspect (optional): Since this model has no explicit size parameter, dimensions are controlled through the prompt description. It is recommended to describe the size at the beginning of the prompt.
- "Mobile wallpaper" -> write at the beginning of the prompt
竖版 9:16or手机海报 9:16 - "Desktop wallpaper/video cover" -> write at the beginning of the prompt
横版 16:9or电影画幅 16:9 - "Avatar" -> write at the beginning of the prompt
1:1 方形构图or1024×1024 方图 - By default, if the user does not explicitly specify the image aspect ratio, keep the image aspect ratio empty (the model adapts automatically).
- "Mobile wallpaper" -> write at the beginning of the prompt
- Response Format (optional): response format, default
url(R2 CDN accelerated link), optionalb64_json(base64 image data). - Note: this model does not support the
size、n、quality、aspect_ratioparameter; passing it may trigger a parameter validation error.
Step 2: Environment Check and Command Execution
-
Check environment: confirm whether the
APIYI_API_KEYenvironment variable is set (usually assumed to be set; only prompt the user if execution fails). -
Build and run the command:
- Try the Node.js version first: if Node is available in the environment (the
nodecommand is available), preferscripts/generate_image.js(zero dependencies, parameters consistent with Python). - If Node is unavailable, use the Python version: use
scripts/generate_image.py。
Text-to-image command template (prefer Node.js):
node scripts/generate_image.js -p "{prompt}" -f "{filename}" [-r {response_format}]Image-to-image command template (prefer Node.js):
node scripts/generate_image.js -p "{edit_instruction}" -i "{input_path}" -f "{output_filename}" [-r {response_format}]Multi-image fusion command template (prefer Node.js):
node scripts/generate_image.js -p "融合图1和图2的风格" -i ref1.png ref2.png -f "merged.png" [-r {response_format}](Optional) Python version command templates (when Node is unavailable):
python scripts/generate_image.py -p "{prompt}" -f "{filename}" [-r {response_format}] python scripts/generate_image.py -p "{edit_instruction}" -i "{input_path}" -f "{output_filename}" [-r {response_format}] - Try the Node.js version first: if Node is available in the environment (the
⏱️ Long-running task handling strategy
1. Pre-task notification
You must inform the user before execution:
- "Image generation has started. It is expected to take 60 to 300 seconds."
2. 🎨 Best practice examples
"Image is being generated. Expected to complete in 60 to 300 seconds...\n⏳ Generating..."
Step 3: Result feedback
- Execution feedback: wait for the terminal command to finish executing.
- Success: inform the user that the image has been generated and point out the save path.
- Failure:
- If it indicates the API Key is missing, guide the user to set the environment variable.
- If it indicates a network error, suggest the user check the network or try again later.
Command-line usage examples
Generate a new image
python scripts/generate_image.py -p "图片描述文本" -f "output.png" [-r url|b64_json]
Example:
# 基础生成
python scripts/generate_image.py -p "一只可爱的橘猫在草地上玩耍" -f "cat.png"
# 指定尺寸(在prompt开头描述)
python scripts/generate_image.py -p "横版 16:9 电影画幅,日落山脉风景" -f "sunset.png"
# 竖版高清图片(适合手机壁纸)
python scripts/generate_image.py -p "竖版 9:16 手机海报,城市夜景" -f "city.png"
(Optional) Node.js version example:
# 基础生成
node scripts/generate_image.js -p "一只可爱的橘猫在草地上玩耍" -f "cat.png"
# 指定尺寸
node scripts/generate_image.js -p "横版 16:9 电影画幅,日落山脉风景" -f "sunset.png"
Edit an existing image
python scripts/generate_image.py -p "编辑指令" -f "output.png" -i "path/to/input.png"
Example:
# 修改风格
python scripts/generate_image.py -p "将图片转换成水彩画风格" -f "watercolor.png" -i "original.png"
# 添加元素
python scripts/generate_image.py -p "在天空添加彩虹" -f "rainbow.png" -i "landscape.png"
# 替换背景
python scripts/generate_image.py -p "将背景换成海滩" -f "beach-bg.png" -i "portrait.png"
(Optional) Node.js version example:
# 修改风格
node scripts/generate_image.js -p "将图片转换成水彩画风格" -f "watercolor.png" -i "original.png"
# 多张参考图融合(最多5张)
node scripts/generate_image.js -p "融合图1和图2的风格" -i ref1.png ref2.png -f "merged.png"
Command-line parameter description
The parameters for the Python and Node.js versions are consistent (short parameters and long parameters are equivalent).
| Parameter | Required | Description |
|---|---|---|
-p / --prompt |
Yes | Image description (text-to-image) or editing instruction (image-to-image). Preserve the user's original complete input. |
-f / --filename |
No | Output image path/filename; if not provided, automatically generate a timestamped PNG filename and write it to the current directory. |
-r / --response-format |
No | Response format:url(default, R2 CDN link) or b64_json(base64 image data). |
-i / --input-image |
No | Input image path for image-to-image; multiple images can be passed (up to 5). Passing this parameter enters editing mode. |
File resource description
| Resource | Description |
|---|---|
scripts/generate_image.js |
Node.js version (zero dependencies, preferred) |
scripts/generate_image.py |
Python version (alternative) |
references/size-guide.md |
Size and aspect ratio control documentation, use when needed, load on demand |
references/batch-template.md |
Batch generation configuration template, use when batch generation is needed, load on demand |
Batch generation
When the user needs to generate multiple images at once (batch generation):
- Load configuration template:references/batch-template.md — includes JSON configuration format description and usage examples
- Obtain/generate JSON file: the user can provide a JSON file themselves, or describe the requirements and the AI will generate it based on the requirements
- Preprocess prompt: ensure each prompt begins with a size description (e.g. "landscape 16:9"), supplement if necessary
global.size_hint - Execute one by one: read the prompts array, execute the generation command one by one, and report the result after each image is completed
- Summary feedback: after completion, inform the number of successes and the list of image paths
Note: total batch task time = single image time (60-300 seconds) × number of images, please inform the user of the estimated duration in advance.
Image aspect ratio description
Since the gpt-image-2-all model has no size parameter, the size is controlled through the prompt description. Verified relatively stable phrasings:
| Requirement | Recommended phrasing |
|---|---|
| Square | 1024×1024 square image / 1:1 square composition |
| Landscape | landscape 16:9 / widescreen 16:9 cinematic frame |
| Portrait | portrait 9:16 / mobile poster 9:16 |
| Ultra-wide banner | banner 21:9 ultra-wide screen |
| Classic print | 4:3 standard frame / 3:2 classic frame |
Tip: describe the size/composition at the beginning of the prompt, and the model will follow it more closely. You can pair it with frame style words (such as cinematic frame, mobile poster, square composition) to further improve consistency.
Response format description
url (default)
By default, returns an R2 CDN accelerated link, valid for about 24 hours. Suitable for direct rendering in web applications. For images that need to be stored long-term, please transfer them to your own object storage immediately after generation.
b64_json
Returns base64-encoded image data (already includes the data:image/png;base64, prefix). Suitable for:
- The server needs to process the image data directly
- Need to write to a local file
- Direct rendering on the frontend
Notes
- The API key must be set, and can be provided via an environment variable or a command-line argument
- Image generation time: about 60 seconds to 300 seconds
- When editing an image, the input image is automatically converted to base64 encoding
- Ensure the output directory has write permission
- This model does not support the
size、n、quality、aspect_ratioparameter - The url field in the default response is an R2 CDN accelerated link, valid for about 24 hours
API Key setup and acquisition
How to get an API Key
If you do not have an API key yet, please go to https://api.apiyi.com to register an account and apply for an API Key.
Steps to obtain:
- Visit https://api.apiyi.com
- Register/log in to your account
- Create an API key in the console
- Copy the key and set it as an environment variable or use it in the command line
Set the API Key
The script obtains the API key from the environment variable APIYI_API_KEY .
Set the environment variable:
# Linux/Mac
export APIYI_API_KEY="your-api-key-here"
# Windows CMD
set APIYI_API_KEY=your-api-key-here
# Windows PowerShell
$env:APIYI_API_KEY="your-api-key-here"
API Endpoint Description
Primary endpoint: POST /v1/chat/completions
Conversational endpoint—compared to /v1/images/generations and /v1/images/edits, the conversational endpoint follows prompts better, and the same endpoint supports both text-to-image and reference-image editing, making multi-turn iteration natural.
- Text-only messages input → text-to-image
- Add image_url (URL or base64 data URL) to messages → reference-image editing
- Keep assistant history messages to continue asking → multi-turn iterative image editing
Model Information
- Model name: gpt-image-2-all
- Image generation speed: about 60-300 seconds
- Output resolution: no explicit size parameter, adaptively determined by the model (recommended to describe in the prompt)
- Default response format: url (R2 CDN accelerated link, default 1-day validity)
- Optional response format: b64_json
- Chinese prompts: ✅ natively supported
- Supported capabilities: text-to-image, single-image editing, multi-image fusion, natural language image editing
- Price: $0.03/image
Author Introduction
- Omnipresent One Piece Fan
- My WeChat official account: Omnipresent Technology