gpt-image-2 Image Generation Skill: Auto-discovering Gateways and Saving Outputs to Disk in Agents

Introduction

In environments such as Cursor and Claude Code, a common way to make an Agent draw images is to hand-write a script that calls the OpenAI-compatible /v1/images/generations endpoint, or to hardcode the base URL and API Key into the conversation. If a gateway only exposes /v1/models without supporting the standard image-generation path, it’s easy to mistake “gpt-image-2 can be listed” for “image generation definitely works.” Below is an introduction to the SkillHub community skill @user_fdb96f95/gpt-image-2 (the gpt-image-2 image-generation skill): it follows a fixed workflow to discover configuration, validate the model, call the API, and save b64_json as a local file.

What Is This

The gpt-image-2 Image Generation Skill is a general-purpose image-generation module for any AI Agent, identified as @user_fdb96f95/gpt-image-2. The current SkillHub version is 1.1.2, source community, category design-media, publisher user_fdb96f95. Official page: SkillHub Skill Page, resource address https://api.skillhub.cn/user_fdb96f95/gpt-image-2.

The skill tag indicates requires_api_key=true: you need to provide your own API Key for an OpenAI-compatible gateway; the skill itself does not store real keys in its documentation.

Core Features

According to the skill package’s SKILL.md, the verified capabilities include:

  1. Automatic discovery of OpenAI-compatible API: it first reads the environment variables OPENAI_BASE_URL / OPENAI_API_KEY and CLAWTO_BASE_URL / CLAWTO_API_KEY; if none are set, it maps fields such as model.base_url, model.api_key, auxiliary.vision.base_url, and auxiliary.vision.api_key from the host’s config.yaml.
  2. Verify gpt-image-2 support: it requests /v1/models using the same base URL and the same set of credentials, confirming that gpt-image-2 exists in the list.
  3. Call the image-generation endpoint: it submits JSON (model, prompt, size, etc.) to {base_url}/images/generations, with a recommended timeout of 180 seconds or longer.
  4. Save a local file: it parses data[0].b64_json in the response and decodes it into a file such as a PNG.
  5. Operational and security conventions: it does not skip SSL verification; the model list and image-generation requests must use the same gateway; if a size is not supported it falls back from 2048x1024 to 1024x1024; it ships with references/clawto-api-notes.md, which documents the non-standard path behavior of some gateways.

Installation & Activation

Install the SkillHub CLI

If it hasn’t been installed yet, you can first check the version:

command -v skillhub && skillhub --version

If not installed, you can run this (CLI only):

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

See https://skillhub.cn/install/skillhub.md for full installation instructions.

Install This Skill

When installing, you must use --dir to point to the current Agent’s skills directory; otherwise it defaults to ./skills/ and may not be recognized. The installation command for this skill, as listed in the index, is:

skillhub install gpt-image-2 --namespace user_fdb96f95 --dir <your skills directory>

Common path examples (from the SkillHub installation documentation):

  • Cursor: ~/.cursor/skills/
  • Claude Code: ~/.claude/skills/
  • Codex: ~/.codex/skills/ or .agents/skills/ under the project

You can also give the following prompt to your Agent, asking it to fetch @user_fdb96f95/gpt-image-2 according to the official installation documentation:

Please install @user_fdb96f95/gpt-image-2 according to https://skillhub.cn/install/skillhub.md.

After installation, restart or refresh the Agent as required by your client so that the skill takes effect.

Configure the API

Inject the following into your shell or host environment (example; replace with real values):

export OPENAI_BASE_URL="https://your-gateway/v1"
export OPENAI_API_KEY="your-key"

The skill also supports the CLAWTO_BASE_URL / CLAWTO_API_KEY naming; the exact discovery order is governed by SKILL.md.

Typical Usage

The steps below match the skill documentation, making them easy to reproduce in a terminal or an Agent session.

1. Check whether environment variables have been configured

python3 - <<'PY'
import os
candidates = [
    ('OPENAI_BASE_URL', 'OPENAI_API_KEY'),
    ('CLAWTO_BASE_URL', 'CLAWTO_API_KEY'),
]
for base_var, key_var in candidates:
    base = os.getenv(base_var)
    key = os.getenv(key_var)
    if base and key:
        print(f'{base_var}={base}')
        print(f'{key_var}=SET')
        break
else:
    print('no_api_found')
PY

2. Verify whether /v1/models contains gpt-image-2

First set API_BASE_URL and API_KEY to the discovered values, then run:

python3 - <<'PY'
import os, json, urllib.request, ssl
base = os.environ['API_BASE_URL'].rstrip('/')
key = os.environ['API_KEY']
url = f'{base}/models'
req = urllib.request.Request(url, headers={'Authorization': f'Bearer {key}'})
ctx = ssl.create_default_context()
with urllib.request.urlopen(req, context=ctx, timeout=30) as r:
    data = json.loads(r.read().decode('utf-8', 'ignore'))
    models = [m.get('id') for m in data.get('data', [])]
    print('has_gpt_image_2=', 'gpt-image-2' in models)
    print(models)
PY

3. Call gpt-image-2 to generate an image

python3 - <<'PY'
import os, json, urllib.request, ssl
base = os.environ['API_BASE_URL'].rstrip('/')
key = os.environ['API_KEY']
api = f'{base}/images/generations'
payload = json.dumps({
    'model': 'gpt-image-2',
    'prompt': 'a stylish female livestream host in a professional streaming studio, smiling, modern lighting, realistic, safe and tasteful, no suggestive pose',
    'size': '1024x1024'
}).encode()
req = urllib.request.Request(api, data=payload, headers={
    'Authorization': f'Bearer {key}',
    'Content-Type': 'application/json'
})
ctx = ssl.create_default_context()
with urllib.request.urlopen(req, context=ctx, timeout=180) as r:
    print(r.status)
    print(r.read().decode('utf-8', 'ignore'))
PY

4. Write the b64_json from the response JSON to a file

First save the previous step’s response as response.json, then decode it:

python3 - <<'PY'
import json, base64, pathlib
body = json.loads(open('response.json').read())
out = pathlib.Path('gpt_image_2.png')
out.write_bytes(base64.b64decode(body['data'][0]['b64_json']))
print(out)
PY

When used in a conversation, you can simply describe the scene in natural language (the skill documentation provides English example prompts, which can be swapped for scenarios such as livestream studios or product showcases). If the user specifies an output directory, the skill requires the Agent to remember that path and use it as the default destination for subsequent writes.

Use Cases & Caveats

Who it’s for

  • Developers already using an OpenAI-compatible gateway whose model list contains gpt-image-2.
  • Teams that want the Agent to follow a unified workflow — “discover config → verify model → generate image → save to disk” — rather than piecing together ad-hoc curl commands each time.

Limitations & gotchas

  • Some gateways only show gpt-image-2 in /v1/models, but the standard /v1/images/generations still returns 404 or requires a different path; the gateway notes bundled with the skill use api.clawto.link as an example to illustrate this case — you cannot judge image-generation availability solely from the model list.
  • Responses are mostly b64_json rather than an image URL; 401, 400, and insufficient balance require checking credentials, size, and account quota respectively.
  • SkillHub page statistics (as of the time the material was retrieved): rating 100000, downloads 10194, installs 2; actual usability still depends on your gateway and Key.

Conclusion

The gpt-image-2 Image Generation Skill turns “discover an OpenAI-compatible API, verify gpt-image-2, call the generation endpoint, and save the file” into fixed, Agent-executable steps, making it suitable as a general-purpose image-generation module attached to environments such as Cursor, Claude Code, and Codex. See https://www.skillhub.cn/skills/user_fdb96f95/gpt-image-2 for installation and details, and the resource entry at https://api.skillhub.cn/user_fdb96f95/gpt-image-2.

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

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

Xiaoye