GPT Image 2 图改图
SpiderHubs OpenAPI 文档:GPT Image 2 图改图,分类 GPT Image 2。接口 POST /openapi/v1/image/gpt-image-2/i2i。📐 完整 size × ratio → W×H 映射表见左侧导航 「Nano Banana 2 文生图」 页面 (所有...
OpId:
img-gpt-image-2-i2i · 最近更新: 2026-05-271. 接口概览
| 项 | 值 |
|---|---|
| 底层模型 | gpt-image-2 |
| 计费 | 1 积分 / 次 |
| 限流 | 30 次 / 分钟 / 用户 |
| 特性 | 基于参考图 + prompt 二次创作;保留原图布局与文字结构 |
2. 基础信息
- Endpoint:
- POST /openapi/v1/image/gpt-image-2/i2i
3. 请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| prompt | string | 是 | 图片描述提示词 |
| size | string | 否 | 分辨率档,可选 1K / 2K / 4K,默认 2K;也兼容直接传 WxH(如 1024x1024)。 |
| ratio | string | 否 | 长宽比,可选 1:1 / 16:9 / 9:16 / 4:3 / 3:4,默认 1:1。 |
| route | int | 否 | 生图线路 1/2,默认 1。不同线路对应不同算力供应商,可在效果/速度/稳定性间切换;同一 prompt 不同 route 风格可能有差异。 |
| image_urls | string[] | 否 | 参考图片 URL 数组(最多 5 张,单张 ≤ 10MB)。与 image_b64 二选一其一即可;两者同时提供时优先用 image_urls。 |
| image_b64 | string | string[] | 否 | 参考图片的 base64(单串或数组,最多 10 张、单张解码后 ≤ 8MB)。裸 base64 或 data: URI 均可,类型自动识别。用于无法提供公网 URL 的场景,作为 image_urls 的替代;两者同时提供时本字段被忽略。注意整个请求体上限 40MB(base64 会膨胀约 33%),多图时各图共享该额度。 |
size × ratio 映射表
📐 完整
size × ratio → W×H 映射表见左侧导航 「Nano Banana 2 文生图」 页面 (所有图片端点共享同一张表)。4. 响应
响应是标准 OpenAI
字段说明:
·
·
·
Python 解码示例:
/v1/images/generations 结构:{ "created": <epoch>, "data": [ { "b64_json": "<base64>" } ] }字段说明:
·
created:服务端时间戳(秒)。·
data[i].b64_json:图片字节的 base64 编码。·
data 数组当前固定 1 个元素(单图返回)。Python 解码示例:
import base64
b = base64.b64decode(res["data"][0]["b64_json"])
open("out.jpg","wb").write(b)请求示例 · cURL
# 方式一:参考图用公网 URL
curl -X POST 'https://api.spiderhubs.com/openapi/v1/image/gpt-image-2/i2i' \
-H 'Authorization: Bearer sk_live_xxxxxxxxxxxxxxxxxxxxxxxx' \
-H 'Content-Type: application/json' \
-d '{
"prompt": "replace background with city skyline at sunset",
"image_urls": ["https://example.com/input.jpg"],
"size": "2K",
"ratio": "16:9",
"route": 1
}'
# 方式二:参考图用本地图片 base64(gpt-image-2 仅取第 1 张,单张 ≤ 8MB)
IMG=$(base64 -w0 input.jpg) # macOS 用: base64 -i input.jpg(再去掉换行)
curl -X POST 'https://api.spiderhubs.com/openapi/v1/image/gpt-image-2/i2i' \
-H 'Authorization: Bearer sk_live_xxxxxxxxxxxxxxxxxxxxxxxx' \
-H 'Content-Type: application/json' \
-d '{
"prompt": "replace background with city skyline at sunset",
"image_b64": "'"$IMG"'",
"size": "2K",
"ratio": "16:9",
"route": 1
}'响应示例
{
"created": 1716345678,
"data": [
{ "b64_json": "/9j/4AAQSkZJRgABAQEBLAEsAAD/..." }
]
}开始调用 SpiderHubs API
使用账户中心生成的 API Key,通过 Authorization: Bearer sk_live_xxx 调用接口。