通过 HTTP API 调用 GPT Image 2、Nano Banana Pro、Nano Banana 2 和 Nano Banana 2 Lite 图片生成服务,兼容 OpenAI 图片接口格式。
在网站登录后,点击顶栏 API 按钮创建 API Key。所有 API 请求需要在 Header 中携带:
Authorization: Bearer sk-your-api-key
返回 OpenAI 兼容格式的可用模型列表,可用于客户端自动发现模型 ID。
curl https://image2free.com/v1/models
{
"object": "list",
"data": [
{
"id": "gpt-image-2",
"object": "model",
"created": 1764547200,
"owned_by": "image2free"
}
]
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| 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 积分;Nano Banana 2 Lite 仅支持 standard(1K),1 积分 |
| model | string | 否 | 模型 ID。不传默认 gpt-image-2。支持下方模型表中的 ID |
| image / image_urls | string[] | 否 | 参考图片,最多 5 张、每张最大 20MB。两个字段等价。支持公网 HTTP(S) URL 或 data URL;出于安全原因不允许访问内网地址 |
| output_format | string | 否 | 输出格式,目前支持 png |
| moderation | string | 否 | GPT Image 模型支持 auto 或 low |
| async | boolean | 否 | 默认为 false,等待生成完成后返回图片 URL;设为 true 时立即返回任务 ID,通过 /v1/tasks/{id} 查询结果 |
| 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 积分 |
| Nano Banana 2 Lite NEW | nano-banana-2-lite | 仅支持 standard(1K),1 积分,支持参考图 |
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",
"output_format": "png",
"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",
"async": true,
"n": 1
}'
curl -X POST https://image2free.com/v1/images/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "nano-banana-2-lite",
"prompt": "快速生成一张干净的产品海报,白色背景,高级光影",
"size": "1:1",
"quality": "standard",
"image": ["https://example.com/reference.png"]
}'
同步模式(默认)会在图片生成完成后返回:
{
"created": 1714000000,
"data": [
{
"url": "https://image2free.com/api/jobs/abc123/image"
}
]
}
异步模式传入 "async": true,接口立即返回:
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "j_abc123"
}
]
}
基于已有图片进行编辑、风格迁移或局部修改(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,映射同生成接口 |
| output_format | string | 否 | 输出格式,目前支持 png |
| moderation | string | 否 | auto 或 low |
| async | boolean | 否 | 默认为 false;设为 true 时立即返回任务 ID |
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" \
-F "output_format=png" \
-F "async=true"
# 使用 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 一致。
通过 job ID 获取已完成任务的图片 URL。任务尚未完成时返回 409 not_ready,生成失败返回 422 generation_failed,文件已过期或被删除返回 410 gone。查询任务进度和失败原因请使用 /v1/tasks/{id}。
提交 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"
}'
查询图片或视频异步任务。状态可能为 queued、running、done 或 error。
curl https://image2free.com/v1/tasks/job-id \
-H "Authorization: Bearer sk-your-api-key"
{
"code": 200,
"data": {
"id": "j_abc123",
"status": "done",
"progress": 100,
"output_available": true,
"result": {
"images": [
{"url": ["https://image2free.com/api/jobs/j_abc123/image"]}
]
}
}
}
任务失败时接口仍返回 HTTP 200,任务状态和失败原因位于 data:
{
"code": 200,
"data": {
"id": "j_abc123",
"status": "error",
"progress": 0,
"output_available": false,
"error": {
"message": "生成超时,请重试",
"type": "generation_failed"
}
}
}
curl https://image2free.com/v1/me \
-H "Authorization: Bearer sk-your-api-key"
{
"id": "user-id",
"email": "you@example.com",
"balance": 42
}
错误响应格式(兼容 OpenAI):
{
"error": {
"message": "Insufficient credits.",
"type": "insufficient_quota",
"code": 402
}
}
| HTTP Code | Type | 说明 |
|---|---|---|
| 401 | unauthorized | API Key 无效或缺失 |
| 403 | forbidden | 账号已封禁,或无权访问该任务 |
| 402 | insufficient_quota | 积分不足 |
| 409 | not_ready | 异步任务仍在排队或生成中 |
| 410 | gone | 生成文件已过期或被删除 |
| 413 | invalid_request_error | 请求体或上传文件过大 |
| 422 | generation_failed | 图片或视频生成失败 |
| 429 | rate_limit_exceeded | 请求过于频繁 |
| 500 | server_error | 服务端错误 |
| 503 | server_busy | 生成队列已满;任务不会继续执行,积分会自动退回 |
| 504 | timeout | 同步生成超时;任务会终止并退回本次积分 |
import requests
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": "nano-banana-2-lite",
"prompt": "把这只狗变成水彩画风格",
"image": ["https://example.com/dog.png"]
}
)
data = resp.json()["data"][0]
# 下载图片
img = requests.get(data["url"]).content
with open("output.png", "wb") as f:
f.write(img)
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: "nano-banana-2-lite",
prompt: "A cat wearing an astronaut helmet on the moon",
size: "1024x1024",
quality: "hd",
// 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