Skip to main content

Overview

This is a custom Python plugin for the Coze platform (coze.cn) that wraps OpenAI’s GPT Image 2 model (gpt-image-2) through the APIYI gateway into a node that Coze workflows can call directly. The plugin ships with complete request construction, error-code classification, content-safety filtering detection, and an Alibaba Cloud OSS upload pipeline. It returns a publicly accessible URL ready for display, saving you from building another result-forwarding step in your Coze workflow.
Project Info
  • 📦 Distribution: shared as a code package (not published on GitHub)
  • 👤 Author: community contribution
  • 🎯 Target platform: Coze (China / global) custom plugins
  • 🔌 Model called: gpt-image-2 (APIYI, released April 21, 2026)
  • 🌐 Gateway: APIYI — direct access from mainland China, no VPN required
  • 📝 The full source code is provided in the ‘Full Plugin Source Code’ section below, ready to copy and use

About the APIYI Gateway

APIYI is a gateway for GPT Image 2 with direct connectivity from mainland China, offering three routes that share a single API Key: APIYI offers three ways to access GPT Image 2:
This plugin uses gpt-image-2 (official relay) by default, fully compatible with the official OpenAI API and supporting full parameter control. If you need faster generation, switch to gpt-image-2-all mode (see below).
Request an API Key (starting with sk-) in the APIYI console. We recommend setting a daily quota limit (e.g. ¥20-50) to keep costs under control.

Core Features

Unified text-to-image / image-to-image entry

Automatically switches between text-to-image (/v1/images/generations) and editing (/v1/images/edits) modes based on whether fileurls is empty — no need to build two separate nodes in your Coze workflow

Direct access from mainland China, no VPN

All requests go through the APIYI gateway (api.apiyi.com) — directly reachable from Chinese networks, with low latency and reliable stability

Multi-reference-image editing

Pass a list of image URLs and the plugin downloads them and injects them into the request as multipart/form-data file uploads — up to 16 reference images (each ≤ 50MB), preserving original image details

Fine-grained error classification

Distinguishes MODERATION_BLOCKED, INVALID_API_KEY, RATE_LIMIT, SERVER_ERROR, TIMEOUT, NO_DATA and other failure causes, making workflow branching easy

Two-stage content-safety detection

Distinguishes input-stage moderation_blocked (400) from output-stage content_filter (200), and returns a clear rejection message when triggered, avoiding pointless retries

Direct OSS upload

The generated base64 image is uploaded straight to Alibaba Cloud OSS — the workflow receives a URL ready to share externally or store

Fine parameter control

Supports quality (low/medium/high/auto), moderation (auto/low), output_format (png/jpeg/webp) and other parameters, so you can tune the generation strategy as needed

Supported Models

The plugin uses gpt-image-2 (official relay) by default, with endpoints https://api.apiyi.com/v1/images/generations (text-to-image) and https://api.apiyi.com/v1/images/edits (image-to-image), and requires a valid APIYI API Key (starting with sk-). To switch routes, change API_BASE in the code to https://vip.apiyi.com/v1 or https://b.apiyi.com/v1.

GPT Image 2 Key Specs

API Endpoints

To switch routes: https://vip.apiyi.com/v1/... or https://b.apiyi.com/v1/.... All routes are functionally identical.

Plugin Architecture

GPT Image 2 Coze plugin architecture diagram The plugin’s core call chain:

Resolution and Size Reference

The plugin selects the size automatically from aspect_ratio and resolution (based on APIYI’s official presets):
Constraints: every dimension must be divisible by 16, aspect ratio ≤ 3:1, total pixels ≤ 8,294,400. Note: 1:1 at 4K outputs 3840×2160 (landscape 16:9), not a square — this is an API limitation, and the effective aspect ratio becomes 16:9. Outputs above 2560×1440 are still experimental; for production, prefer the preset sizes.

Input and Output Parameters

Input (Input)

Output (Output)

Deployment Steps

1

Step 1: Prepare an APIYI API Key and OSS credentials

  • Request an API Key (starting with sk-) in the APIYI console; we recommend setting a daily quota limit (e.g. ¥20-50)
  • Create an OSS bucket on Alibaba Cloud and a RAM sub-account with oss:PutObject permission on that bucket
  • Record the AccessKey ID, AccessKey Secret, Bucket name, and Endpoint (e.g. oss-cn-beijing.aliyuncs.com)
2

Step 2: Search for and install the plugin in the Coze plugin marketplace

  1. Go to Coze workspace → Plugins → Plugin marketplace
  2. Search for ‘GPT Image 2’ or ‘APIYI’ to find this plugin
  3. Open the plugin card to review the details, then click ‘Add’ to install it into your workspace Coze plugin marketplace search
3

Step 3: Copy the plugin code

Paste the full Python code from the ‘Full Plugin Source Code’ section below into the Coze IDE, and replace the Alibaba Cloud OSS configuration at the top with your own:
4

Step 4: Configure metadata and input/output parameters

Configure the Input / Output field types and required flags as shown below, matching the args.input fields in the code:Input parameter configuration:Coze plugin basic infoCoze plugin input parameter configurationOutput parameter configuration:Coze plugin output parameter configuration (part 1)Coze plugin output parameter configuration (part 2)
5

Step 5: Test and publish

  • Fill in test parameters in the Coze IDE (start with quality=low + resolution=1K + a simple prompt to verify the APIYI pipeline)
  • Once tests pass, click ‘Publish’ and drag the plugin into any workflow

Error Classification Strategy

The plugin does not just report success=True/False — it classifies the failure cause in the following priority order, so your Coze workflow can branch accordingly:

Two-Stage Content Filtering

GPT Image 2 uses two-stage content-safety filtering, unlike Nano Banana Pro:

Common moderation_blocked Triggers

APIYI-Specific Errors

Expected Latency by Resolution/Quality

Recommendation: use resolution=1K + quality=medium for day-to-day work (20-40 s per image), and resolution=4K + quality=high for final deliverables. With quality=auto (omitted or set to auto), the plugin applies a uniform 360-second timeout, and the API decides the actual quality level.

Full Plugin Source Code

Below is the complete code of coze-gptimage2.py, ready to paste straight into the Coze IDE. Only the OSS configuration at the top needs to be changed before use.
The plugin source is kept verbatim as contributed; comments and user-facing error strings are in Chinese and can be freely localized for your workflow.
coze-gptimage2.py

Optional: gpt-image-2-all Fast Mode

If you need faster generation (30-60s) and do not care about size parameter control, you can switch the plugin to APIYI’s gpt-image-2-all (reverse edition), called via the Chat Completions endpoint. This mode costs $0.03/image and returns image URLs directly, with no base64 parsing needed. The core change (just replace the generate_image function):
How to switch: replace generate_image(...) in handler() with generate_image_chat(...). The only inputs needed are prompt, apikey, and optionally fileurls.

Using It in a Coze Workflow

After publishing the plugin, drag the plugin node into the Coze workflow editor and wire it up as follows:
We recommend pairing this with the Feishu Base AI image generation solution. The combined setup lets ops/design teammates batch-generate images just by filling in prompts in a Feishu table, without opening any code. Simply swap the Nano Banana Pro plugin in that solution for this one.

Comparison with Nano Banana Pro

FAQ

Yes. The ‘Full Plugin Source Code’ section of this page contains the complete coze-gptimage2.py. Just change the OSS configuration and API_BASE at the top and paste it straight into the Coze IDE — nothing else to request.If you also need:
So each user can be handed a different APIYI API Key. In the Coze workflow, put a ‘per-user apikey dispatch’ dictionary node in front that matches the caller’s name to their API Key — convenient for usage accounting and access control.
APIYI is a gateway with direct connectivity from mainland China. Its API Keys also start with sk-, but:
  • Direct access from mainland China, no VPN required
  • Requested and managed in the APIYI console
  • Supports daily/monthly quota limits, making cost control easy
  • One Key works for both Nano Banana Pro and GPT Image 2
All three routes are functionally identical — use any of them with the same API Key:Just change the API_BASE variable in the code to switch.
Downstream Coze workflow nodes (especially Feishu field shortcuts) mostly require an accessible URL to convert the result into an image attachment. Returning base64 directly makes the data shuttle back and forth through the workflow — poor performance, and the Feishu side cannot render it directly. An OSS link is also convenient for long-term archiving and external sharing.
It means the input prompt or reference image triggered content-safety filtering. This error does not need a retry — retrying yields the same result. Suggestions:
  1. Rewrite the prompt wording
  2. Avoid real-person names, copyrighted character names, and names of living artists
  3. Avoid sexual innuendo, violence, gore, and other sensitive descriptions
This usually means the model completed inference (already billed) but the output was blocked by the content-safety filter (content_filter). Suggestions:
  1. Redesign the entire visual scene rather than tweaking wording
  2. Try a completely different prompt direction
  3. Lowering quality can sometimes get past the stricter output filter
GPT Image 2’s high quality takes 145-280 seconds even at 1K, and 4K can exceed 600 seconds. The plugin already sets a 900-second timeout for high quality. If it still times out:
  1. Debug your prompt with quality=medium first
  2. Check the APIYI console for rate limiting
  3. Try switching routes and retrying
  4. Reduce the number of concurrent calls
  5. Consider the gpt-image-2-all mode (30-60s per image)
GPT Image 2 does not support it. If you need transparent backgrounds, use the Nano Banana Pro plugin instead.
No. The parameter list of APIYI’s official-relay gpt-image-2 is not fully identical to OpenAI’s; thinking is not among the parameters APIYI supports. For fine control over output quality, use the quality parameter (low / medium / high / auto) instead.Other unsupported parameters include:
  • response_format — the response always returns b64_json
  • n — fixed at 1
  • background: "transparent" — transparent backgrounds are not supported
  • input_fidelity — locked to high; passing it returns a 400 error
Both plugins use the same APIYI platform, and one API Key works for both. Recommendations:

Feishu Base AI Image Generation Solution

The perfect companion to this plugin: connect the whole Coze workflow to Feishu Base so ops teammates can batch-generate images by filling in a table

Nano Banana Pro Coze Plugin

Another Coze image-generation solution, built on Gemini 3 Pro Image, sharing the same APIYI Key with GPT Image 2

APIYI GPT Image 2 Docs

Full documentation, parameter reference and code examples for APIYI’s official-relay GPT Image 2

APIYI GPT Image 2-All Docs

APIYI’s reverse-edition Chat Completions endpoint docs ($0.03/image, 30-60s per image)

APIYI Console

Manage API keys, check usage and balance, set quota limits

GPT Image 2 Common Error Fixes

moderation_blocked 400 error diagnosis and mitigation strategies