apiyi-gpt-image-2-all-gen

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

图片生成与编辑(GPT Image 2 All)Skills

Image Generation and Editing (GPT Image 2 All) Skills

基于API易平台的ChatGPT最新生图gpt-image-2-all模型实现图片生成技能,可以通过自然语言帮助用户生成图片,通过API易国内代理服务访问,支持Node.js和Python两种运行环境。gpt-image-2-all是API易平台上线的一款GPT图像生成官逆模型,以 $0.03/张 的极具竞争力的按次计费定价,约60秒到300秒出图,支持文生图/单图编辑/多图融合/自然语言改图,文字还原度高、内容限制少、原生支持中文提示词。
This image generation skill is implemented based on the latest ChatGPT image generation model gpt-image-2-all from APIYI Platform. It can help users generate images through natural language, accessed via APIYI's domestic proxy service, and supports both Node.js and Python runtime environments. gpt-image-2-all is an official reverse ChatGPT image generation model launched on APIYI Platform, priced at a highly competitive $0.03 per image on a pay-per-use basis. It takes approximately 60 to 300 seconds to generate an image, supporting text-to-image generation, single image editing, multi-image fusion, and natural language-based image modification, with high text restoration accuracy, few content restrictions, and native support for Chinese prompts.

使用指引

Usage Guide

遵循以下步骤:
Follow these steps:

第1步:分析需求与参数提取

Step 1: Requirement Analysis and Parameter Extraction

  1. 明确意图:区分用户是需要【文生图】(生成新图片)还是【图生图】(编辑/修改现有图片)或【多图融合】。
  2. 提示词(Prompt)分析
    • 使用用户原始完整输入:把用户输入的原始完整问题需求描述(原文)直接作为
      -p
      提示词的主体,避免自行改写、总结或二次创作,防止细节丢失。
    • 需要补充时先确认:如果信息不足(例如缺少风格、主体数量、镜头语言、场景细节、文字内容、禁止元素等),先向用户提问确认;用户确认后,再把补充内容以"追加"的方式拼接到原始提示词后。
    • 样例:
      • 用户输入:"帮我生成一张猫的图片,风格要可爱一点。"
      • 正例说明:直接使用用户输入作为提示词:
        -p "帮我生成一张猫的图片,风格要可爱一点。"
      • 反例说明:擅自改写为"生成一张可爱风格的猫的图片"会丢失用户原始输入的细节和语气。
      • 如果需要补充细节(例如颜色、背景等),先提问确认:"你希望猫是什么颜色的?背景有什么要求吗?"用户回答后,再追加到提示词中:
        -p "帮我生成一张猫的图片,风格要可爱一点。猫是橘色的,背景是草地。"
  3. 关键参数整理
    • Prompt(必需):提示词分析后的最终提示词(默认=用户原始完整且一致的输入;仅在用户确认后才追加补充信息)。
    • Filename(可选):输出图片文件名/路径(需包含文件随机标识,避免重复)。不传则脚本会自动生成带时间戳的文件名。建议根据内容生成合理文件名(例如
      cat_in_garden.png
      ),避免使用通用名。
    • Size/Aspect(可选):由于该模型无显式size参数,尺寸通过prompt描述控制。建议在prompt开头描述尺寸。
      • "手机壁纸" -> 在prompt开头写
        竖版 9:16
        手机海报 9:16
      • "电脑壁纸/视频封面" -> 在prompt开头写
        横版 16:9
        电影画幅 16:9
      • "头像" -> 在prompt开头写
        1:1 方形构图
        1024×1024 方图
      • 默认若用户未明确指定图片比例,保持图片比例为空(由模型自适应)。
    • Response Format(可选):响应格式,默认
      url
      (R2 CDN加速链接),可选
      b64_json
      (base64图片数据)。
    • 注意:该模型不支持
      size
      n
      quality
      aspect_ratio
      参数,传入可能触发参数校验错误。
  1. Clarify Intent: Distinguish whether the user needs [Text-to-Image] (generate new images), [Image-to-Image] (edit/modify existing images), or [Multi-Image Fusion].
  2. Prompt Analysis:
    • Use the user's original complete input: Directly use the user's original full question and requirement description as the main body of the
      -p
      prompt. Avoid rewriting, summarizing, or secondary creation on your own to prevent loss of details.
    • Confirm first when supplementation is needed: If information is insufficient (e.g., missing style, number of subjects, shot language, scene details, text content, prohibited elements, etc.), ask the user for confirmation first; after the user confirms, append the supplementary content to the original prompt in an "appended" manner.
    • Examples:
      • User input: "Help me generate a picture of a cat, with a cute style."
      • Correct example: Use the user's input directly as the prompt:
        -p "Help me generate a picture of a cat, with a cute style."
      • Incorrect example: Unauthorized rewriting to "Generate a cute-style cat picture" will lose the details and tone of the user's original input.
      • If details need to be supplemented (e.g., color, background, etc.), ask for confirmation first: "What color do you want the cat to be? Any requirements for the background?" After the user replies, append it to the prompt:
        -p "Help me generate a picture of a cat, with a cute style. The cat is orange, and the background is grass."
  3. Key Parameter Organization:
    • Prompt (Required): The final prompt after analysis (default = the user's original complete and consistent input; only append supplementary information after user confirmation).
    • Filename (Optional): Output image filename/path (must include a random 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 (e.g.,
      cat_in_garden.png
      ), avoid using generic names.
    • Size/Aspect (Optional): Since the model has no explicit size parameter, the size is controlled by prompt description. It is recommended to describe the size at the beginning of the prompt.
      • "Mobile wallpaper" -> Write
        Vertical 9:16
        or
        Mobile poster 9:16
        at the start of the prompt
      • "Computer wallpaper/video cover" -> Write
        Horizontal 16:9
        or
        Movie aspect ratio 16:9
        at the start of the prompt
      • "Avatar" -> Write
        1:1 Square composition
        or
        1024×1024 Square image
        at the start of the prompt
      • Default: If the user does not explicitly specify the image ratio, leave it blank (adaptive by the model).
    • Response Format (Optional): Response format, default is
      url
      (R2 CDN accelerated link), optional
      b64_json
      (base64 image data).
    • Note: The model does not support
      size
      ,
      n
      ,
      quality
      ,
      aspect_ratio
      parameters; passing them may trigger parameter validation errors.

第2步:环境检查与命令执行

Step 2: Environment Check and Command Execution

  1. 检查环境:确认
    APIYI_API_KEY
    环境变量是否已设置(通常假定已设置,若运行失败再提示用户)。
  2. 构建并运行命令
    • 优先尝试 Node.js 版本:如果环境有 Node(
      node
      命令可用),优先使用
      scripts/generate_image.js
      (零依赖,参数与 Python 保持一致)。
    • Node 不可用再用 Python 版本:使用
      scripts/generate_image.py
    文生图命令模板(优先 Node.js):
    bash
    node scripts/generate_image.js -p "{prompt}" -f "{filename}" [-r {response_format}]
    图生图命令模板(优先 Node.js):
    bash
    node scripts/generate_image.js -p "{edit_instruction}" -i "{input_path}" -f "{output_filename}" [-r {response_format}]
    多图融合命令模板(优先 Node.js):
    bash
    node scripts/generate_image.js -p "融合图1和图2的风格" -i ref1.png ref2.png -f "merged.png" [-r {response_format}]
    (可选)Python 版本命令模板(Node 不可用时)
    bash
    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}]
  1. Check Environment: Confirm whether the
    APIYI_API_KEY
    environment variable is set (usually assumed to be set; prompt the user if the operation fails).
  2. Build and Run Commands:
    • Priority: Node.js version: If Node is available in the environment (the
      node
      command works), prefer using
      scripts/generate_image.js
      (zero dependencies, parameters consistent with Python).
    • Use Python version if Node is unavailable: Use
      scripts/generate_image.py
      .
    Text-to-Image Command Template (Priority: Node.js):
    bash
    node scripts/generate_image.js -p "{prompt}" -f "{filename}" [-r {response_format}]
    Image-to-Image Command Template (Priority: Node.js):
    bash
    node scripts/generate_image.js -p "{edit_instruction}" -i "{input_path}" -f "{output_filename}" [-r {response_format}]
    Multi-Image Fusion Command Template (Priority: Node.js):
    bash
    node scripts/generate_image.js -p "Merge the styles of image 1 and image 2" -i ref1.png ref2.png -f "merged.png" [-r {response_format}]
    (Optional) Python Version Command Template (When Node is Unavailable):
    bash
    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}]

⏱️ 长时间任务处理策略

⏱️ Long-running Task Handling Strategy

1. 任务前提示

1. Pre-task Prompt

执行前必须告知用户
  • "图片生成已启动,预计需要60秒到300秒"
Must inform the user before execution:
  • "Image generation has started, it is expected to take 60 to 300 seconds"

2. 🎨 最佳实践示例

2. 🎨 Best Practice Example

"图片生成中,预计60秒到300秒完成...\n⏳ 正在生成..."
"Image generation in progress, expected to complete in 60 to 300 seconds...
⏳ Generating..."

第3步:结果反馈

Step 3: Result Feedback

  1. 执行反馈:等待终端命令执行完毕。
  2. 成功:告知用户图片已生成,并指出保存路径。
  3. 失败
    • 若提示 API Key 缺失,请指导用户设置环境变量。
    • 若提示网络错误,建议用户检查网络或稍后重试。
  1. Execution Feedback: Wait for the terminal command to complete execution.
  2. Success: Inform the user that the image has been generated and indicate the save path.
  3. Failure:
    • If prompted with missing API Key, guide the user to set the environment variable.
    • If prompted with network error, suggest the user check the network or try again later.

命令行使用样例

Command Line Usage Examples

生成新图片

Generate New Images

bash
python scripts/generate_image.py -p "图片描述文本" -f "output.png" [-r url|b64_json]
示例:
bash
undefined
bash
python scripts/generate_image.py -p "Image description text" -f "output.png" [-r url|b64_json]
Example:
bash
undefined

基础生成

Basic generation

python scripts/generate_image.py -p "一只可爱的橘猫在草地上玩耍" -f "cat.png"
python scripts/generate_image.py -p "A cute orange cat playing on the grass" -f "cat.png"

指定尺寸(在prompt开头描述)

Specify size (describe at the start of the prompt)

python scripts/generate_image.py -p "横版 16:9 电影画幅,日落山脉风景" -f "sunset.png"
python scripts/generate_image.py -p "Horizontal 16:9 Movie aspect ratio, sunset mountain scenery" -f "sunset.png"

竖版高清图片(适合手机壁纸)

Vertical high-definition image (suitable for mobile wallpaper)

python scripts/generate_image.py -p "竖版 9:16 手机海报,城市夜景" -f "city.png"

**(可选)Node.js 版本示例:**
```bash
python scripts/generate_image.py -p "Vertical 9:16 Mobile poster, city night view" -f "city.png"

**(Optional) Node.js Version Example**:
```bash

基础生成

Basic generation

node scripts/generate_image.js -p "一只可爱的橘猫在草地上玩耍" -f "cat.png"
node scripts/generate_image.js -p "A cute orange cat playing on the grass" -f "cat.png"

指定尺寸

Specify size

node scripts/generate_image.js -p "横版 16:9 电影画幅,日落山脉风景" -f "sunset.png"
undefined
node scripts/generate_image.js -p "Horizontal 16:9 Movie aspect ratio, sunset mountain scenery" -f "sunset.png"
undefined

编辑已有图片

Edit Existing Images

bash
python scripts/generate_image.py -p "编辑指令" -f "output.png" -i "path/to/input.png"
示例:
bash
undefined
bash
python scripts/generate_image.py -p "Editing instruction" -f "output.png" -i "path/to/input.png"
Example:
bash
undefined

修改风格

Modify style

python scripts/generate_image.py -p "将图片转换成水彩画风格" -f "watercolor.png" -i "original.png"
python scripts/generate_image.py -p "Convert the image to watercolor style" -f "watercolor.png" -i "original.png"

添加元素

Add elements

python scripts/generate_image.py -p "在天空添加彩虹" -f "rainbow.png" -i "landscape.png"
python scripts/generate_image.py -p "Add a rainbow to the sky" -f "rainbow.png" -i "landscape.png"

替换背景

Replace background

python scripts/generate_image.py -p "将背景换成海滩" -f "beach-bg.png" -i "portrait.png"

**(可选)Node.js 版本示例:**
```bash
python scripts/generate_image.py -p "Change the background to a beach" -f "beach-bg.png" -i "portrait.png"

**(Optional) Node.js Version Example**:
```bash

修改风格

Modify style

node scripts/generate_image.js -p "将图片转换成水彩画风格" -f "watercolor.png" -i "original.png"
node scripts/generate_image.js -p "Convert the image to watercolor style" -f "watercolor.png" -i "original.png"

多张参考图融合(最多5张)

Merge multiple reference images (up to 5)

node scripts/generate_image.js -p "融合图1和图2的风格" -i ref1.png ref2.png -f "merged.png"
undefined
node scripts/generate_image.js -p "Merge the styles of image 1 and image 2" -i ref1.png ref2.png -f "merged.png"
undefined

命令行参数说明

Command Line Parameter Description

Python 与 Node.js 版本参数保持一致(短参数与长参数等价)。
参数必填说明
-p
/
--prompt
图片描述(文生图)或编辑指令(图生图)。保留用户原始完整输入。
-f
/
--filename
输出图片路径/文件名;不传则自动生成带时间戳的 PNG 文件名,并写入当前目录。
-r
/
--response-format
响应格式:
url
(默认,R2 CDN链接)或
b64_json
(base64图片数据)。
-i
/
--input-image
图生图输入图片路径;可传多张(最多5张)。传入该参数即进入编辑模式。
Parameters are consistent between Python and Node.js versions (short parameters are equivalent to long parameters).
ParameterRequiredDescription
-p
/
--prompt
YesImage description (for text-to-image) or editing instruction (for image-to-image). Keep the user's original complete input.
-f
/
--filename
NoOutput image path/filename; if not provided, a PNG filename with timestamp will be automatically generated and saved to the current directory.
-r
/
--response-format
NoResponse format:
url
(default, R2 CDN link) or
b64_json
(base64 image data).
-i
/
--input-image
NoInput image path for image-to-image; multiple images can be passed (up to 5). Passing this parameter enters editing mode.

文件资源说明

File Resource Description

资源说明
scripts/generate_image.js
Node.js 版本(零依赖,优先使用)
scripts/generate_image.py
Python 版本(备选)
references/size-guide.md
尺寸与比例控制文档,需要时使用,按需加载
references/batch-template.md
批量生成配置模板,需要批量生成时使用,按需加载
ResourceDescription
scripts/generate_image.js
Node.js version (zero dependencies, preferred)
scripts/generate_image.py
Python version (alternative)
references/size-guide.md
Size and ratio control document, 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

当用户需要一次性生成多张图片(批量生成)时:
  1. 加载配置模板references/batch-template.md — 包含 JSON 配置格式说明和使用示例
  2. 获取/生成 JSON 文件:用户可自行提供 JSON 文件,或描述需求后 AI 根据需求生成
  3. 预处理 prompt:确保每个 prompt 开头包含尺寸描述(如"横版 16:9"),必要时补充
    global.size_hint
  4. 逐个执行:读取 prompts 数组,逐个执行生成命令,每张完成后反馈结果
  5. 汇总反馈:完成后告知成功数量、图片路径列表
注意:批量任务总时间 = 单张时间(60-300秒) × 图片数量,请提前告知用户预估时长。
When the user needs to generate multiple images at once (batch generation):
  1. Load Configuration Template: references/batch-template.md — includes JSON configuration format description and usage examples
  2. Obtain/Generate JSON File: Users can provide their own JSON file, or describe requirements and let AI generate it based on the needs
  3. Preprocess Prompt: Ensure each prompt starts with size description (e.g., "Horizontal 16:9"), supplement
    global.size_hint
    if necessary
  4. Execute One by One: Read the prompts array, execute generation commands one by one, and feed back results after each image is completed
  5. Summarize Feedback: After completion, inform the user of the number of successful images and the list of image paths
Note: Total time for batch tasks = single image time (60-300 seconds) × number of images. Please inform the user of the estimated duration in advance.

图片比例说明

Image Ratio Description

由于gpt-image-2-all模型没有size参数,尺寸通过prompt描述控制。经验证较稳定的写法:
需求推荐写法
方形1024×1024 方图 / 1:1 方形构图
横版横版 16:9 / 宽屏 16:9 电影画幅
竖版竖版 9:16 / 手机海报 9:16
超宽横幅横幅 21:9 超宽银幕
经典印刷4:3 标准画幅 / 3:2 经典画幅
技巧:在prompt开头描述尺寸/构图,模型遵循度更高。可搭配画幅风格词(如 电影画幅、手机海报、方形构图)进一步提升一致性。
Since the gpt-image-2-all model has no size parameter, the size is controlled by prompt description. The following verified stable expressions are recommended:
RequirementRecommended Expression
Square1024×1024 Square image / 1:1 Square composition
HorizontalHorizontal 16:9 / Wide screen 16:9 Movie aspect ratio
VerticalVertical 9:16 / Mobile poster 9:16
Ultra-wide bannerBanner 21:9 Ultra-wide screen
Classic printing4:3 Standard aspect ratio / 3:2 Classic aspect ratio
Tip: Describe the size/composition at the beginning of the prompt for better model compliance. You can match it with aspect ratio style words (e.g., movie aspect ratio, mobile poster, square composition) to further improve consistency.

响应格式说明

Response Format Description

url(默认)

url (Default)

默认返回 R2 CDN 加速链接,有效期约24小时。适用于Web应用直接渲染。对于需要长期保存的图片,请生成后立即转存到自己的对象存储。
Returns an R2 CDN accelerated link by default, valid for approximately 24 hours. Suitable for direct rendering in web applications. For images that need long-term storage, please transfer and save them to your own object storage immediately after generation.

b64_json

b64_json

返回 base64 编码的图片数据(已含
data:image/png;base64,
前缀)。适用于:
  • 服务端需要直接处理图片数据
  • 需要写入本地文件
  • 前端直接渲染
Returns base64 encoded image data (with
data:image/png;base64,
prefix included). Suitable for:
  • Server-side direct image data processing
  • Need to write to local files
  • Direct rendering on the frontend

注意事项

Notes

  • API密钥必须设置,可通过环境变量或命令行参数提供
  • 图片生成时间:约60秒到300秒
  • 编辑图片时,输入图片会自动转换为base64编码
  • 确保输出目录有写入权限
  • 该模型不支持
    size
    n
    quality
    aspect_ratio
    参数
  • 默认响应的 url 字段是 R2 CDN 加速链接,有效期约24小时
  • API Key must be set, which can be provided via environment variable or command line parameter
  • Image generation time: approximately 60 to 300 seconds
  • When editing images, the input image will be automatically converted to base64 encoding
  • Ensure the output directory has write permission
  • The model does not support
    size
    ,
    n
    ,
    quality
    ,
    aspect_ratio
    parameters
  • The default response url field is an R2 CDN accelerated link, valid for approximately 24 hours

API Key设置与获取

API Key Setup and Acquisition

如何获取API Key

How to Obtain API Key

如果你还没有API密钥,请前往 https://api.apiyi.com 注册账号并申请API Key。
获取步骤:
  1. 访问 https://api.apiyi.com
  2. 注册/登录你的账号
  3. 在控制台中创建API密钥
  4. 复制密钥并设置环境变量或在命令行中使用
If you don't have an API Key yet, please go to https://api.apiyi.com to register an account and apply for an API Key.
Acquisition Steps:
  1. Visit https://api.apiyi.com
  2. Register/log in to your account
  3. Create an API Key in the console
  4. Copy the key and set it as an environment variable or use it in the command line

设置API Key

Set API Key

脚本从环境变量
APIYI_API_KEY
获取API密钥。
设置环境变量:
bash
undefined
The script obtains the API Key from the environment variable
APIYI_API_KEY
.
Set Environment Variable:
bash
undefined

Linux/Mac

Linux/Mac

export APIYI_API_KEY="your-api-key-here"
export APIYI_API_KEY="your-api-key-here"

Windows CMD

Windows CMD

set APIYI_API_KEY=your-api-key-here
set APIYI_API_KEY=your-api-key-here

Windows PowerShell

Windows PowerShell

$env:APIYI_API_KEY="your-api-key-here"
undefined
$env:APIYI_API_KEY="your-api-key-here"
undefined

API端点说明

API Endpoint Description

主推端点:POST /v1/chat/completions

Recommended Endpoint: POST /v1/chat/completions

对话式端点——相比
/v1/images/generations
/v1/images/edits
,对话式端点对提示词遵循更好,并且同一端点同时支持文生图与带参考图改图,可以天然做多轮迭代。
  • 仅输入文本 messages → 文生图
  • messages 中加入 image_url(URL 或 base64 data URL)→ 带参考图改图
  • 保留 assistant 历史消息继续追问 → 多轮迭代改图
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 generation and reference image-based modification, naturally enabling multi-round iterations.
  • Only input text messages → Text-to-image generation
  • Add image_url (URL or base64 data URL) to messages → Reference image-based modification
  • Retain assistant historical messages and continue asking → Multi-round iterative image modification

模型信息

Model Information

  • 模型名:gpt-image-2-all
  • 出图速度:约 60-300 秒
  • 输出分辨率:无显式 size 参数,由模型自适应(建议在 prompt 中描述)
  • 默认响应格式:url(R2 CDN 加速链接,默认 1 天有效期)
  • 可选响应格式:b64_json
  • 中文提示词:✅ 原生支持
  • 支持能力:文生图、单图编辑、多图融合、自然语言改图
  • 价格:$0.03/张
  • Model Name: gpt-image-2-all
  • Image Generation Speed: Approximately 60-300 seconds
  • Output Resolution: No explicit size parameter, adaptive by the model (recommended to describe in 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 generation, single image editing, multi-image fusion, natural language-based image modification
  • Price: $0.03 per image

作者介绍

Author Introduction

  • 爱海贼的无处不在
  • 我的微信公众号:无处不在的技术
  • Everywhere who loves One Piece
  • My WeChat Official Account: Ubiquitous Technology",