通过 HTTP API 调用 GPT Image 2、Nano Banana Pro 和 Nano Banana 2 图片生成服务,兼容 OpenAI 图片接口格式。
在网站登录后,点击顶栏 API 按钮创建 API Key。所有 API 请求需要在 Header 中携带:
Authorization: Bearer sk-your-api-key
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| prompt | string | ✅ | 图片描述(支持中英文) |
| size | string | 否 | 尺寸或比例(默认 1024x1024)。支持像素格式如 1024x1024,或比例格式如 1:1/16:9/9:16/4:3/3:4/3:2/2:3/21:9/2:1 等,也支持 auto。具体像素输出分辨率由 quality 控制 |
| quality | string | 否 | standard(1K,默认),hd(2K),uhd(4K)。GPT Image 2 分别为 1/2/3 积分;Nano Banana Pro 固定 10 积分;Nano Banana 2 固定 5 积分 |
| model | string | 否 | 模型 ID。不传默认 gpt-image-2。支持下方模型表中的 ID |
| image / image_urls | string[] | 否 | 参考图片,最多 5 张。两个字段等价,推荐兼容 APIQIK 格式时使用 image: ["url1","url2"]。支持 HTTP URL 或 data URL(data:image/png;base64,...) |
| n | int | 否 | 固定为 1,每次生成 1 张图片 |
| 显示名称 | 模型 ID | 计费 |
|---|---|---|
| GPT Image 2 | gpt-image-2 | standard/hd/uhd = 1/2/3 积分 |
| Nano Banana Pro | gemini-3-pro-image-preview gemini-3-pro-image-preview-2k gemini-3-pro-image-preview-4k | 固定 10 积分 |
| Nano Banana 2 | gemini-3.1-flash-image-preview gemini-3.1-flash-image-preview-2k gemini-3.1-flash-image-preview-4k | 固定 5 积分 |
curl -X POST https://image2free.com/v1/images/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "一只戴着宇航员头盔的猫咪,在月球上弹吉他,赛博朋克风格",
"size": "16:9",
"quality": "hd",
"n": 1,
"image": ["https://example.com/cat.png"]
}'
curl -X POST https://image2free.com/v1/images/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-pro-image-preview-4k",
"prompt": "Create a cinematic product photo of a glass perfume bottle on black marble",
"size": "16:9",
"n": 1
}'
{
"created": 1714000000,
"data": [
{
"b64_json": "/9j/4AAQSkZJRg...",
"url": "https://image2free.com/api/jobs/abc123/image"
}
]
}
基于已有图片进行编辑、风格迁移或局部修改(mask)。兼容 OpenAI /v1/images/edits 接口,支持 OpenAI SDK 的 client.images.edit() 调用。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| prompt | string | ✅ | 编辑指令(支持中英文) |
| image | file[] | 否 | 一个或多个源图片文件(最多 5 张,每张 ≤ 50MB)。OpenAI SDK 使用此字段名 |
| mask | file | 否 | PNG 遮罩图,透明区域表示需要编辑的部分。仅对第一张图片生效 |
| model | string | 否 | 模型 ID,不传默认 gpt-image-2 |
| size | string | 否 | 尺寸或比例(默认 1024x1024),同生成接口 |
| quality | string | 否 | low/medium/high/auto,映射同生成接口 |
curl -X POST https://image2free.com/v1/images/edits \
-H "Authorization: Bearer sk-your-api-key" \
-F "prompt=Put a crown on the cat's head" \
-F "image=@cat.png" \
-F "model=gpt-image-2"
# 使用 mask 局部编辑
curl -X POST https://image2free.com/v1/images/edits \
-H "Authorization: Bearer sk-your-api-key" \
-F "prompt=Replace the background with a sunset beach" \
-F "image=@photo.png" \
-F "mask=@mask.png" \
-F "model=gpt-image-2"
与 /v1/images/generations 完全一致,返回 b64_json 和 url。
通过 job ID 获取生成的图片(base64 + URL)。
提交 Seedance 2.0、VEO3.1 或 HappyHorse 1.0 视频任务,接口异步返回任务 ID,再用 /v1/tasks/{id} 查询结果。HappyHorse 1.0 当前按 720p = 22 积分/秒、1080p = 38 积分/秒 计费。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 否 | 支持 doubao-seedance-2.0*、veo3.1-fast、veo3.1-quality、veo3.1-lite、happyhorse-1.0 |
| prompt | string | 通常必填 | 除 HappyHorse 的 first_frame_image 模式外,视频描述必填 |
| resolution | string | 否 | Seedance 支持 480p/720p;VEO3 支持 720p/1080p/4k;HappyHorse 支持 720p/1080p |
| duration | int | 否 | Seedance 为 4-15 秒,按秒扣费;VEO3 固定 8 秒,按次扣费;HappyHorse 为 3-15 秒,按秒扣费,编辑模式按源视频时长计费 |
| size / aspect_ratio | string | 否 | VEO3 支持 16:9/9:16;Seedance 另支持方形、4:3、21:9、adaptive;HappyHorse 支持 16:9/9:16/1:1/4:3/3:4 |
| first_frame_image / video_url | string | 否 | HappyHorse 专用:first_frame_image 走 I2V;video_url 走 EDIT |
| audio_setting / watermark | mixed | 否 | HappyHorse 编辑模式支持 audio_setting: auto/origin;HappyHorse 支持 watermark |
| generation_type / enable_gif / official_fallback | mixed | 否 | VEO3 专用:generation_type 支持 frame/reference;enable_gif 仅支持 720p;official_fallback 不支持 lite |
| image_urls / video_urls / audio_urls | string[] | 否 | 公网可访问的参考素材 URL。VEO3 图片最多 3 张;HappyHorse 的编辑模式中建议使用 video_url 而不是 video_urls |
curl -X POST https://image2free.com/v1/videos/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "doubao-seedance-2.0-fast",
"prompt": "城市夜景延时摄影,镜头缓慢推进",
"resolution": "720p",
"size": "16:9",
"duration": 5,
"generate_audio": true
}'
curl -X POST https://image2free.com/v1/videos/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "veo3.1-fast",
"prompt": "海豚在碧蓝海洋中跳跃",
"resolution": "1080p",
"aspect_ratio": "16:9",
"duration": 8
}'
curl -X POST https://image2free.com/v1/videos/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "happyhorse-1.0",
"prompt": "A little girl walking down the road, cinematic feel",
"resolution": "1080P",
"size": "16:9",
"duration": 5,
"seed": 42
}'
续写已完成的 VEO3 视频。路径里的 task_id 是本站返回的任务 ID,模型必须与原视频一致。
curl -X POST https://image2free.com/v1/videos/job-id/remix \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "veo3.1-fast",
"prompt": "猫咪继续在草地上奔跑,蝴蝶飞向远方",
"raw": false,
"aspect_ratio": "16:9",
"resolution": "720p"
}'
curl https://image2free.com/v1/tasks/job-id \
-H "Authorization: Bearer sk-your-api-key"
curl https://image2free.com/v1/me \
-H "Authorization: Bearer sk-your-api-key"
{
"id": "user-id",
"email": "you@example.com",
"credits": 42
}
错误响应格式(兼容 OpenAI):
{
"error": {
"message": "Insufficient credits.",
"type": "insufficient_quota",
"code": 402
}
}
| HTTP Code | Type | 说明 |
|---|---|---|
| 401 | unauthorized | API Key 无效或缺失 |
| 402 | insufficient_quota | 积分不足 |
| 429 | rate_limit_exceeded | 请求过于频繁 |
| 500 | server_error | 服务端错误 |
import requests, base64
resp = requests.post(
"https://image2free.com/v1/images/generations",
headers={"Authorization": "Bearer sk-your-api-key"},
json={"model": "gpt-image-2", "prompt": "一只可爱的柴犬在樱花树下", "size": "1024x1024"}
)
# 带参考图片的编辑请求
resp = requests.post(
"https://image2free.com/v1/images/generations",
headers={"Authorization": "Bearer sk-your-api-key"},
json={
"model": "gemini-3.1-flash-image-preview-2k",
"prompt": "把这只狗变成水彩画风格",
"image": ["https://example.com/dog.png"]
}
)
data = resp.json()["data"][0]
# 保存图片
img_bytes = base64.b64decode(data["b64_json"])
with open("output.png", "wb") as f:
f.write(img_bytes)
print("Saved to output.png")
const resp = await fetch("https://image2free.com/v1/images/generations", {
method: "POST",
headers: {
"Authorization": "Bearer sk-your-api-key",
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "gemini-3-pro-image-preview",
prompt: "A cat wearing an astronaut helmet on the moon",
size: "1024x1024",
// image: ["https://example.com/cat.png"] // 可选:参考图片
})
});
const { data } = await resp.json();
console.log("Image URL:", data[0].url);
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://image2free.com/v1"
)
result = client.images.generate(
model="gpt-image-2",
prompt="赛博朋克城市夜景,霓虹灯",
size="1024x1024",
n=1
)
print(result.data[0].url)
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://image2free.com/v1"
)
# 使用参考图编辑
result = client.images.edit(
model="gpt-image-2",
image=[open("cat.png", "rb")],
prompt="Put a crown on the cat's head"
)
print(result.data[0].url)
# 使用 mask 局部编辑
result = client.images.edit(
model="gpt-image-2",
image=[open("photo.png", "rb")],
mask=open("mask.png", "rb"),
prompt="Replace the background with a sunset beach"
)
print(result.data[0].url)
© 2026 GPT Image 2 · image2free.com