gpt-image-2-fast
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "gpt-image-2-fast" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-5d57dbf4e82265a1bc2a9e661972efa273fad2dfce8a4463730d7272bb053649. Verify the upstream source and version against https://skillhub.cn/skills/user_a125fe92/gpt-image-2-fast before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
An AI image-generation skill based on the gpt-image-2 model, generating images via an OpenAI-compatible API.
Introduction source: third_party · user_a125fe92 · 1.0.2 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Audience
- Translation pending; see source documentation.
- Software, accounts and paid services
- Translation pending; see source documentation.
- Limits and differences
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: "gpt-image-2-fast"
description: "基于 gpt-image-2 模型的 AI 图片生成技能,通过 OpenAI 兼容 API 生成图片"gpt-image-2 图片生成器
概述
通过 OpenAI 兼容 API 调用 gpt-image-2 模型生成图片。支持自定义尺寸。
核心设计:
- Python 代码只从
os.environ读取凭证,不硬编码 - 优先直接调用
/images/generations生成图片,生成成功即结束 - 仅当生成失败(如 400 模型不支持)时,再查询
/v1/models排查问题 - 一次
python -c完成 API 调用 + 解码保存,不将 b64_json 取出后二次传递 - 用户对话中提供的凭证通过
export写入环境变量,供后续复用
适用场景
当你需要:
- 在对话中直接生成图片
- 生成图片并保存为本地文件
- 作为任何 AI Agent 的通用生图模块
Python 依赖
- 标准库:
os,json,urllib,ssl,base64,pathlib - 无需第三方包
尺寸规则
| 项目 | 说明 |
|---|---|
| 最小尺寸 | 768×768 |
| 最大尺寸 | 3840×3840 |
| 约束 | 宽和高都必须能被 16 整除 |
| 格式 | {宽}x{高},如 1024x1024、1536x1024 |
校验逻辑:
def validate_size(width: int, height: int) -> str:
if not (768 <= width <= 3840 and 768 <= height <= 3840):
raise ValueError("尺寸超出范围 (768~3840)")
if width % 16 != 0 or height % 16 != 0:
raise ValueError("宽和高必须能被 16 整除")
return f"{width}x{height}"
操作流程总览
1. 设置凭证(env / export)
↓
2. 直接调用 /images/generations(生成图片)
↓
┌─ 成功 ─→ 解码 b64_json → 保存 PNG → SUCCESS
│
└─ 失败 ─→ 判断错误类型
├─ 400 模型不支持 → 查询 /v1/models → 调整参数重试
├─ 401 → 检查凭证
├─ timeout → 重试
└─ 其他 → 报告错误
核心原则:先试再说,失败了再查原因,不预检。
凭证获取流程
1. 检查环境变量
先检查系统环境变量 GPT_IMAGE_API_KEY 和 GPT_IMAGE_BASE_URL 是否已设置。
2a. 已设置 → 直接使用
Python 代码直接从 os.environ 读取,无需做任何额外操作。
2b. 未设置 → 向用户询问 → export 到环境变量
提示用户提供 API Key 和 Base URL,收到后用 export 写入当前 shell 环境:
export GPT_IMAGE_API_KEY='<用户提供的 key>'
export GPT_IMAGE_BASE_URL='<用户提供的 base url>'
之后所有 Python 代码统一从 os.environ 读取,不再需要任何特殊处理。
核心流程:一次性生成并保存
一次 python -c 完成全部工作:调用 API → 检查响应 → 解码 b64_json → 保存 PNG → 输出结果路径。
python -c "
import os, json, urllib.request, ssl, base64, pathlib, sys
base = os.environ.get('GPT_IMAGE_BASE_URL', '').rstrip('/')
key = os.environ.get('GPT_IMAGE_API_KEY', '')
if not base or not key:
print('错误: 未设置 GPT_IMAGE_API_KEY 或 GPT_IMAGE_BASE_URL', file=sys.stderr)
sys.exit(1)
api = f'{base}/images/generations'
payload = json.dumps({
'model': 'gpt-image-2',
'prompt': 'a cute shiba inu dog, high quality, realistic',
'size': '1024x1024',
'n': 1
}).encode()
req = urllib.request.Request(api, data=payload, headers={
'Authorization': f'Bearer {key}',
'Content-Type': 'application/json'
})
ctx = ssl.create_default_context()
try:
with urllib.request.urlopen(req, context=ctx, timeout=180) as r:
body = json.loads(r.read().decode('utf-8', 'ignore'))
except Exception as e:
print(f'API 请求失败: {e}', file=sys.stderr)
sys.exit(1)
if 'data' not in body or len(body['data']) == 0:
print(f'响应中没有 data 字段: {body}', file=sys.stderr)
sys.exit(1)
item = body['data'][0]
if 'b64_json' in item:
out = pathlib.Path('gpt_image_2.png')
out.write_bytes(base64.b64decode(item['b64_json']))
print(f'SUCCESS:{out}')
elif 'url' in item:
print(f'URL:{item[\"url\"]}')
else:
print(f'未知响应格式: {item}', file=sys.stderr)
sys.exit(1)
"
⚠️ 注意:
prompt和size根据用户需求替换。SUCCESS:xxx前缀用于程序化判断结果。
完整执行示例
场景:用户首次使用,提供凭证后生成图片
用户:画一只可爱的柴犬,1024x1024
步骤:
- 检查
GPT_IMAGE_API_KEY和GPT_IMAGE_BASE_URL→ 不存在 - 提示用户提供
- 用户提供后:
export GPT_IMAGE_API_KEY='sk-xxx'; export GPT_IMAGE_BASE_URL='https://...' - 直接调用
/images/generations尝试生成(更换 prompt 和 size) 5a. 成功 → 输出SUCCESS:gpt_image_2.png→present_files展示 5b. 失败(400 模型不支持) → 查询/v1/models确认可用模型 → 调整参数或告知用户
场景:环境变量已存在,直接生成
用户:画一张山水画,1536x1024
步骤:
- 检查环境变量 → 已存在,跳过询问
- 直接执行
python -c调用/images/generations(更换 prompt 和 size) - 成功则展示结果;失败则查
/v1/models排查
错误处理
401 Unauthorized
- 检查 API Key 是否正确
- 检查 Base URL 和 API Key 是否来自同一套配置
- 确认
export后环境变量已正确注入(可执行echo $GPT_IMAGE_API_KEY验证)
400 / 不支持模型
注意:这是生成失败后的排查步骤,不是前置预检。 生成图片本身直接调 /images/generations,遇到 400 错误(如模型不支持)时,才查询 /v1/models 确认该 gateway 上是否真的存在 gpt-image-2 模型:
python -c "
import os, json, urllib.request, ssl
base = os.environ.get('GPT_IMAGE_BASE_URL', '').rstrip('/')
key = os.environ.get('GPT_IMAGE_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)
"
⚠️ 确认
/v1/models和/v1/images/generations使用的是同一 gateway,不要混用。
证书错误
- 优先检查系统证书链、代理和网络环境
- 不要通过跳过证书校验来规避
请求超时
- gpt-image-2 可能生成较慢,超时建议 180 秒
- 超时可重试一次
余额不足
- 出现
insufficient balance说明是账户额度问题,不是接口问题
注意事项
- 输出文件:生成图片保存为当前工作目录下的
gpt_image_2.png - 一次性完成:API 调用 + b64_json 解码 + 保存 PNG,全部在同一个
python -c中完成,不将 b64_json 取出后在 AI 对话中二次传递 - 凭证持久化:用户对话中提供的凭证通过
export写入环境变量,当前 shell 会话中后续命令可直接使用,无需重复提供 - 结果判断:成功输出
SUCCESS:文件名,失败输出到 stderr,方便 AI 判断是否生成功 - 展示结果:生成成功后用
present_files展示图片给用户 - 重试:超时可重试一次;其他错误根据类型给出明确提示
安全原则
- 不在技能文档中保存真实密钥
- 不提供跳过 SSL 证书验证的示例
- 优先使用环境变量注入 API Key
- 如果接口不可用,先检查网络、证书、额度与配置,再重试
- 验证
/v1/models与/v1/images/generations时必须使用同一个 base URL 和同一组凭证
Current listing version
1.0.2
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供基于 gpt-image-2 模型的 AI 图片生成能力,满足用户高频生图需求
- 支持自定义尺寸与本地文件保存,具备明确实用场景
Highlights
- description 清晰描述技能功能与核心能力,触发词精准完整
Highlights
- 文档结构完整,涵盖全流程与异常处理,提供端到端示例
- frontmatter 规范,章节划分清晰,符合最佳实践
Highlights
- 凭证通过环境变量安全注入,避免硬编码
- 覆盖主要异常类型并提供明确排查指引
- 一次性完成 API 调用与解码保存,逻辑闭环可靠
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Save or modify files
Confirm the output directory and whether existing files will be replaced. Back up important files and prefer a new output directory.
Mentioned in main document · lines 134 -
Accounts, secrets or authorization
Use a dedicated least-privilege account. Keep secrets out of public content and command logs; verify the receiving service and tenant.
Mentioned in main document · lines 80, 172, 173, 222, 224
Domains or addresses referenced in the document
These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.
- ...
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Translation pending; see source documentation.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.