GPT-image2 & Nano-Banana via Mid-Relay API
Paste the following prompt into your AI chat to install this skill:
Please follow https://skillhub.cn/install/skillhub.md to install @user_2c58fc0f/ch12893719743826428329324.
About this skill
The Problem It Solves
When leveraging AI for image generation, developers or creators often seek the flexibility to use models from different providers, such as GPT-image2 or Nano-Banana (e.g., Gemini-based image models). However, interfacing directly with multiple official APIs creates management overhead: separate account sign-ups, juggling different API keys, handling disparate calling formats, and potentially incurring higher costs. A relay station (or API proxy) is a common solution to this problem, acting as an aggregation layer between the user and the models. But how to efficiently and securely call these models through a relay still requires a standardized tooling workflow.
How It Works
This skill encapsulates the complexity into a streamlined command-line workflow via a Python script named api_image.py. Its core capabilities and key steps are as follows:
1. Intelligent Configuration & Initialization
- Automatic Protocol Selection: Based on the user's chosen model type (e.g., GPT-image2 or Banana/Gemini), the script automatically determines whether to use the openai or gemini protocol, eliminating the need for manual specification.
- Secure Configuration Saving: During first-time use, an Agent guides the user to input the relay's Base URL, Model ID, and API Key. The script then saves this configuration securely to the local file ~/.api-image/config.json, preventing key leakage.
- Connectivity Verification: After configuration, the script automatically runs a low-cost test generation to ensure the settings are correct and the relay is reachable.
2. Core Generation Capabilities
- Text-to-Image: Generates a new image based solely on a text prompt. Configuration details do not need to be re-supplied for each call.
- Image-to-Image: Supports editing and generation based on a reference image. Notably, for the OpenAI protocol (e.g., GPT-image2), the script strictly adheres to the official requirement by calling the /v1/images/edits endpoint and actually uploading the reference image, ensuring full functionality.
- Flexible Response Handling: Processes both Base64 data and image URL responses from the relay, and automatically corrects the file extension (e.g., .png, .jpeg) based on the actual image bytes.
3. Key Operational Rules
- The script follows a clear configuration priority: Command Arguments > Environment Variables > Local Config File > Default Values.
- For timeouts or ambiguous responses, no automatic retry is performed to prevent unexpected costs.
Scope and Caveats
This skill is focused on providing a reliable, concise API calling channel, not a full-featured image generation platform. Please note the following when using it:
- Supported Scope:
- Supports basic text-to-image, single/multi-image reference generation, and multi-image editing under the OpenAI protocol.
- Input formats supported include PNG, JPEG, and WebP.
-
Does NOT provide: Mask-based inpainting, conversational multi-turn generation state management, or platform-specific metadata processing.
-
Known Limitations:
- The GPT-image2 model does not support transparent background generation; the script will reject the
--background transparentparameter. -
Requires a runtime environment of Python 3.9 or higher and relies solely on Python's standard library, avoiding the need for complex third-party dependencies.
-
Error Handling Recommendations:
- For
401/403errors, first verify the validity of the API Key and account balance. - For
404/405errors, check if theBase URLis correct and if the relay has enabled the corresponding model protocol. - For
429(rate limiting) or5xx(server errors), report the situation but should not retry consecutively. - On timeout or connection interruption, the result status is unknown; avoid automatically resending the request.
In summary, this is a practical utility script aimed at simplifying the relay calling process. Its stability and privacy ultimately depend on the service quality of the relay provider chosen by the user.
Use Cases
- During initial relay API setup, need to automatically identify and configure the OpenAI protocol for GPT-image2, save credentials, and generate a test image to verify endpoint accessibility.
- As a designer, need to call GPT-image2's `/v1/images/edits` endpoint via a relay to upload multiple reference images for creative compositing and editing.
- Receiving a 401 error when calling an image API, need to use the error code guidance to check and re-verify the API key, account balance, and the relay's model permission settings.
- Seeking to quickly switch between different image generation models provided by a relay (e.g., from Gemini to GPT) by simply changing the model ID and immediately performing a text-to-image task with the new model.
Best For
- Independent content creator: Needs to regularly generate customized visuals for social media but prefers not to apply for and manage separate API keys for each AI image model.
- Small design team lead: Clients require outputs in multiple AI visual styles, and seeks a unified tool to simplify calling and configuring APIs for different image generation models.
- Technical integration developer: Plans to embed image generation capabilities into proprietary applications or workflows, but wants to streamline interfacing with multiple underlying model APIs via a single relay.
- AI product demonstrator: Needs to quickly compare output effects of models like GPT-image2 and Nano-Banana during teaching or presentations, requiring a tool that can conveniently switch between and invoke different models.
Related Skills
Restyle a short video into a new visual style while preserving core elements such as characters, actions, and composition, suitable for various creative conversions like anime, illustration, ink wash, etc.
Create Douyin vertical video covers from topics, hooks, or materials with support for creative generation, image synthesis, and refinement.
An AI tool that transforms real photos into specified illustration styles while preserving subject recognition.
An engineering-driven solution that integrates design styles, UX workflows, design systems, and multi-platform implementation to solve cross-project design consistency.