通过 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;出于安全原因不允许访问内网地址 |
| 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",
"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"
}
]
}
基于已有图片进行编辑、风格迁移。兼容 OpenAI /v1/images/edits 接口,支持 OpenAI SDK 的 client.images.edit() 调用。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| prompt | string | ✅ | 编辑指令(支持中英文) |
| image | file[] | ✅ | 一个或多个源图片文件(最多 5 张,每张 ≤ 50MB)。OpenAI SDK 使用此字段名 |
| model | string | 否 | 模型 ID,不传默认 gpt-image-2 |
| size | string | 否 | 尺寸或比例(默认 1024x1024),同生成接口 |
| quality | string | 否 | low/medium/high/auto,映射同生成接口 |
| 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 "async=true"
# 参考图编辑
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 "model=gpt-image-2"
同步和异步响应格式均与 /v1/images/generations 一致。
通过 job ID 获取已完成任务的图片 URL。任务尚未完成时返回 409 not_ready,生成失败返回 422 generation_failed,文件已过期或被删除返回 410 gone。查询任务进度和失败原因请使用 /v1/tasks/{id}。
异步提交视频任务,返回 task_id,再用任务查询接口轮询。当前视频单价为限时特价(标价 × 0.7)。
可用模型:minimax-h3(MiniMax H3,2K,4–15 秒)、doubao-seedance-2.0 / doubao-seedance-2.0-fast、veo3.1-fast / veo3.1-quality / veo3.1-lite、happyhorse-1.0。
curl https://image2free.com/v1/videos/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "minimax-h3",
"prompt": "一个男孩在海边打篮球,黄昏,海浪拍岸,电影感运镜",
"duration": 5,
"resolution": "2k",
"aspect_ratio": "16:9"
}'
| 字段 | 类型 | 说明 |
|---|---|---|
| model | string | 必填。如 minimax-h3 |
| prompt | string | 必填。视频描述 |
| duration | int | 秒数。MiniMax-H3:4–15,默认 5 |
| resolution | string | MiniMax-H3 仅 2k |
| aspect_ratio / size | string | 如 16:9、9:16、1:1;文生建议传具体比例 |
| first_frame_image | string | 首帧图 URL(图生) |
| image_with_roles | object[] | 带角色图片:first_frame / last_frame / reference_image |
| image_urls | string[] | 参考图(一律按参考图处理,最多 9) |
| video_urls | string[] | 参考视频,最多 3 |
| audio_urls | string[] | 参考音频,最多 3;不能单独使用 |
注意:首尾帧字段与参考素材(image_urls / video_urls / audio_urls / reference_image)互斥,混用会返回 400。
{
"code": 200,
"data": [
{ "status": "submitted", "task_id": "j_abc123" }
]
}
用 GET /v1/tasks/{task_id} 查询进度与结果;成功后输出视频 URL,失败自动退款。
查询图片/视频异步任务。状态可能为 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("photo.png", "rb")],
prompt="Replace the background with a sunset beach"
)
print(result.data[0].url)
© 2026 GPT Image 2 · image2free.com