通过 HTTP API 调用图片和视频生成服务。图片接口兼容 OpenAI SDK;视频接口为异步任务接口。
在网站登录后,点击顶栏 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"
}
]
}
图片接口用 size 传比例或像素尺寸,用 quality 传分辨率档位。视频接口用 aspect_ratio 或 size 传比例,用 resolution 传清晰度。
| 模型 | model | size 支持值 | quality | 备注 |
|---|---|---|---|---|
| GPT Image 2 | gpt-image-2 | auto;1:1、4:3、3:4、3:2、2:3、16:9、9:16、4:5、5:4、2:1、1:2、21:9、9:21;支持像素尺寸如 1024x1024、1536x1024、1350x900 | standard / hd / uhd | 像素尺寸会按最长边自动提升计费档位:≤2048 为 1K,≤2688 为 2K,更高为 4K |
| GPT Image 2.5 Flare | gpt-image-2.5-flare | auto;1:1、4:3、3:4、3:2、2:3、16:9、9:16、4:5、5:4、2:1、1:2、21:9、9:21;支持像素尺寸 | standard / hd / uhd | 1K = 0.7 积分/张(原价 1),2K/4K = 3.5 积分/张(原价 5);出图更快,支持参考图 |
| GPT Image 2.5 Sunburst | gpt-image-2.5-sunburst | auto;1:1、4:3、3:4、3:2、2:3、16:9、9:16、4:5、5:4、2:1、1:2、21:9、9:21;支持像素尺寸 | standard / hd / uhd | 1K = 0.7 积分/张(原价 1),2K/4K = 3.5 积分/张(原价 5);画质更佳,支持参考图 |
| Nano Banana Pro | gemini-3-pro-image-preview | auto;1:1、3:2、2:3、4:3、3:4、16:9、9:16、4:5、5:4、21:9;支持自定义像素尺寸 | standard / hd / uhd | 固定 7 积分/张,支持参考图 |
| Nano Banana 2 | gemini-3.1-flash-image-preview | auto;1:1、3:2、2:3、4:3、3:4、16:9、9:16、4:5、5:4、21:9、1:4、4:1、1:8、8:1;支持自定义像素尺寸 | standard / hd / uhd | 固定 3.5 积分/张,支持参考图 |
| Nano Banana 2 Lite | nano-banana-2-lite | auto;1:1、3:2、2:3、4:3、3:4、16:9、9:16、4:5、5:4、21:9、1:4、4:1、1:8、8:1 | 仅 standard | 0.7 积分/张;不支持 1024x1024、1350x900 这类自定义像素尺寸 |
| 模型 | model | aspect_ratio / size | resolution | duration | 素材能力 |
|---|---|---|---|---|---|
| MiniMax H3 | minimax-h3 | 16:9、9:16、1:1、4:3、3:4、21:9、adaptive | 2k | 4-15 秒,默认 5 | 支持图片角色、参考图、参考视频、参考音频;最多 9 张图、3 个视频、3 个音频 |
| Seedance 2.0 标准 | doubao-seedance-2.0 | 16:9、9:16、1:1、4:3、3:4、21:9、adaptive | 480p、720p、1080p | 4-15 秒,默认 5 | 支持参考图、图片角色、参考视频、参考音频、生成音频 |
| Seedance 2.0 快速 | doubao-seedance-2.0-fast | 16:9、9:16、1:1、4:3、3:4、21:9、adaptive | 480p、720p、1080p | 4-15 秒,默认 5 | 支持参考图、图片角色、参考视频、参考音频、生成音频 |
| VEO3.1 Fast | veo3.1-fast | 16:9、9:16 | 720p、1080p、4k | 固定 8 秒 | 支持图片生成视频、首帧、Remix;最多 3 张参考图 |
| VEO3.1 Quality | veo3.1-quality | 16:9、9:16 | 720p、1080p、4k | 固定 8 秒 | 支持首帧/尾帧模式和 Remix;参考图模式限制更严 |
| VEO3.1 Lite | veo3.1-lite | 16:9、9:16 | 720p、1080p、4k | 固定 8 秒 | 不支持参考图、不支持 Remix、不支持 official_fallback |
| HappyHorse 1.0 | happyhorse-1.0 | 16:9、9:16、1:1、4:3、3:4 | 720p、1080p | 3-15 秒,默认 5;视频编辑时按源视频时长 | 支持首帧图、参考图、视频编辑、audio_setting、水印 |
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| prompt | string | ✅ | 图片描述(支持中英文) |
| model | string | 否 | 模型 ID。不传默认 gpt-image-2。可用值见「模型能力速查」 |
| size | string | 否 | 尺寸或比例。默认 1024x1024。比例写 16:9、1:1、auto;自定义像素写 1350x900。Nano Banana 2 Lite 不支持像素尺寸,只能传 auto 或比例 |
| quality | string | 否 | 分辨率档位:standard = 1K,hd = 2K,uhd = 4K。兼容 low/medium/auto = standard,high = hd。Lite 仅支持 standard |
| image_urls | string[] | 否 | 参考图片 URL,最多 5 张、每张最大 20MB。支持公网 HTTP(S) URL 或 data URL;不允许访问内网地址 |
| response_format | string | 否 | 与 OpenAI 一致:url(默认,返回图片链接)或 b64_json(直接返回 Base64 图片数据)。仅同步模式生效 |
| async | boolean | 否 | 默认为 false,等待生成完成后返回图片 URL;设为 true 时立即返回任务 ID,通过 /v1/tasks/{id} 查询结果 |
| background | string | 否 | 传 transparent 生成透明背景(抠图/贴纸)。按模型与档位开放:GPT Image 2 支持 1K;GPT Image 2.5 Flare / Sunburst 支持 2K / 4K。Gemini 系列不支持(上游会静默忽略)。当前档位没有可用渠道时任务会失败并自动退还积分 |
| output_format | string | 否 | 当前渠道忽略该字段,输出固定为 PNG(透明背景因此天然带 alpha 通道) |
| mask_url | string | 否 | 局部重绘遮罩,PNG 且带透明通道:透明像素所在区域会被重新生成,其余保持不变。尺寸需与那张参考图一致,必须同时传 image_urls,且 image_urls 只能传一张 |
| n | int | 否 | 生成张数,1~8,默认 1。每张单独计费;某张失败会自动退还该张积分,其余成功图片照常返回 |
传 size 时先查模型能力表。示例:GPT Image 2 可传 1350x900;Nano Banana 2 Lite 应传 16:9 或 auto,不要传 1024x1024。
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_urls": ["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",
"prompt": "Create a cinematic product photo of a glass perfume bottle on black marble",
"size": "16:9",
"quality": "uhd",
"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_urls": ["https://example.com/reference.png"]
}'
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": "A cute cartoon orange cat sticker, thick white outline, flat vector style",
"size": "1:1",
"quality": "standard",
"background": "transparent",
"output_format": "png"
}'
# 局部重绘:只把遮罩透明区域重新生成(把天空换成日落)\
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": "Turn the masked area into a warm desert sunset",
"size": "1:1",
"quality": "standard",
"image_urls": ["https://example.com/photo.png"],
"mask_url": "https://example.com/mask.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。多图时重复传 -F "image=@a.png" |
| model | string | 否 | 模型 ID,不传默认 gpt-image-2。可用值见「模型能力速查」 |
| size | string | 否 | 尺寸或比例,默认 1024x1024。Lite 不支持像素尺寸,只能传 auto 或比例 |
| quality | string | 否 | standard/hd/uhd;兼容 low/medium/high/auto。Lite 仅支持 standard |
| mask | file | 否 | 局部重绘遮罩,带透明通道的 PNG,透明像素所在区域会被重新生成,尺寸需与 image 一致。必须只传一张 image(多图时上游取哪张当底图不可靠,传多张会返回 400)。需要渠道支持:GPT Image 2 的 1K/2K/4K、GPT Image 2.5 的 2K/4K |
| background | string | 否 | 与生成接口一致,传 transparent 输出透明背景 |
| output_format | string | 否 | 同生成接口:当前渠道忽略,输出固定为 PNG |
| response_format | string | 否 | 同生成接口:url(默认)或 b64_json |
| n | int | 否 | 生成张数,1~8,默认 1,计费与退款规则同生成接口 |
| async | boolean/string | 否 | 默认为 false;可传 true/1/yes/on,立即返回任务 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=nano-banana-2-lite" \
-F "size=1:1" \
-F "quality=standard"
# 局部重绘:只有 mask 的透明区域会被重新生成
curl -X POST https://image2free.com/v1/images/edits \
-H "Authorization: Bearer sk-your-api-key" \
-F "prompt=Turn the masked area into a warm desert sunset" \
-F "image=@photo.png" \
-F "mask=@mask.png" \
-F "model=gpt-image-2" \
-F "size=1:1"
同步和异步响应格式均与 /v1/images/generations 一致;response_format=b64_json 时返回 data[0].b64_json。
图片接口按 OpenAI 官方请求格式实现,可直接使用 OpenAI 官方 SDK / 客户端(把 base_url 指向 https://image2free.com/v1 即可)。下面逐项列出支持情况,避免参数被静默忽略。
| OpenAI 字段 | 接口 | 支持 | 说明 |
|---|---|---|---|
| prompt | 两者 | ✅ | 必填 |
| model | 两者 | ✅ | 不传默认 gpt-image-2 |
| size | 两者 | ✅ | 比例或像素,另支持 auto |
| quality | 两者 | ✅ | low/medium/high/auto 映射到 1K/2K/4K 档 |
| n | 两者 | ✅ | 支持 1~8,每张图单独计费、失败单独退款。同步模式返回 n 张;async=true 时返回 task_ids 数组 |
| background | 两者 | ✅ | transparent 输出透明背景(按模型与档位开放) |
| output_format | 两者 | ❌ | 当前渠道忽略该字段(实测请求 webp / jpeg 均返回 PNG)。可以传,但输出格式以 PNG 为准 |
| response_format | 两者 | ✅ | url(默认)/ b64_json,仅同步模式 |
| image | edits | ✅ | 可多张(≤5) |
| mask | edits | ✅ | 带 alpha 的 PNG,透明区被重绘;必须只配一张 image |
| output_compression | 两者 | ❌ | 实测无效果(压缩 10 与 90 输出字节数无差异),需要压缩请自行处理返回的图片 |
| moderation | 两者 | ❌ | 不支持;渠道自带内容审核,命中会返回错误并自动退还积分 |
| partial_images / stream | 两者 | ❌ | 不支持流式返回,请用 async=true + /v1/tasks/{id} 轮询 |
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://image2free.com/v1",
)
# 透明贴纸(1K)
sticker = client.images.generate(
model="gpt-image-2",
prompt="A cute cartoon cat sticker, flat vector style",
size="1:1",
quality="high",
background="transparent",
output_format="png",
response_format="b64_json",
)
# 局部重绘:mask 的透明区域会被重新生成
edited = client.images.edit(
model="gpt-image-2",
image=open("photo.png", "rb"),
mask=open("mask.png", "rb"),
prompt="Replace the masked area with a warm sunset",
size="1:1",
)
通过 job ID 获取已完成任务的图片 URL。需要直接下载文件时请求 GET /v1/images/{id}/content,接口会跳转到图片文件。任务尚未完成时返回 409 not_ready,生成失败返回 422 generation_failed,文件已过期或被删除返回 410 gone。查询任务进度和失败原因请使用 /v1/tasks/{id}。
异步提交视频任务,接口立即返回 task_id,再用 GET /v1/tasks/{id} 轮询结果。当前视频单价为限时特价(标价 × 0.7)。
| 字段 | 类型 | 必填 | 适用模型 | 说明 |
|---|---|---|---|---|
| model | string | 是 | 全部 | 视频模型 ID,见「模型能力速查」 |
| prompt | string | 通常是 | 全部 | 视频描述。HappyHorse 首帧图生且没有源视频时可为空,其它情况必填;MiniMax H3 最长 7000 字符 |
| aspect_ratio | string | 否 | 全部 | 输出比例,优先级高于 size。支持值按模型不同,见上方视频模型表 |
| size | string | 否 | 全部 | 等同 aspect_ratio,二选一即可。未传时优先使用 adaptive,否则使用模型默认比例 |
| resolution | string | 否 | 全部 | 清晰度。MiniMax H3 仅 2k;Seedance 为 480p/720p/1080p;VEO 为 720p/1080p/4k;HappyHorse 为 720p/1080p |
| duration | int | 否 | 除 VEO 固定 8 秒外 | 视频秒数。MiniMax / Seedance:4-15 秒;HappyHorse:3-15 秒;不传用模型默认值 |
| generate_audio | boolean | 否 | Seedance | 是否生成音频;其它视频模型传入会返回 400 |
| first_frame_image | string | 否 | MiniMax、VEO Fast/Quality、HappyHorse | 首帧图片 URL,用于图生视频 |
| image_urls | string[] | 否 | MiniMax、Seedance、VEO Fast、HappyHorse | 参考图片 URL。MiniMax / Seedance / HappyHorse 最多 9 张;VEO Fast 最多 3 张;VEO Quality 不支持普通参考图模式 |
| image_with_roles | object[] | 否 | MiniMax、Seedance | 带角色的图片数组,格式:{"url":"https://...","role":"first_frame"}。role 支持 first_frame、last_frame、reference_image |
| video_urls | string[] | 否 | MiniMax、Seedance | 参考视频 URL,最多 3 个;不能和首帧/尾帧图混用 |
| audio_urls | string[] | 否 | MiniMax、Seedance | 参考音频 URL,最多 3 个;不能单独使用,必须同时提供参考图或参考视频 |
| seed | int | 否 | MiniMax、Seedance、HappyHorse | 随机种子,用于提高结果可复现性 |
| return_last_frame | boolean | 否 | Seedance | 成功后在任务结果中返回末帧图片 URL |
| generation_type | string | 否 | VEO Fast/Quality | frame 或 reference。VEO Quality 仅支持 frame;frame 模式需要刚好 2 张图 |
| enable_gif | boolean | 否 | VEO | 仅 VEO 且仅 720p 可用 |
| official_fallback | boolean | 否 | VEO Fast/Quality | 是否允许官方通道兜底;VEO Lite 不支持 |
| video_url | string | 否 | HappyHorse | 源视频 URL,用于视频编辑。编辑时系统按源视频时长计费,源视频至少 3 秒 |
| audio_setting | string | 否 | HappyHorse 编辑模式 | auto 或 origin;只在传 video_url 的编辑模式可用 |
注意:首帧/尾帧字段与参考素材(image_urls / video_urls / audio_urls / reference_image)互斥,混用会返回 400。VEO Lite 不接受参考图;音频参考不能单独传。
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"
}'
curl 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": "720p",
"aspect_ratio": "16:9",
"image_urls": ["https://example.com/frame.png"],
"generation_type": "reference"
}'
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": 6,
"resolution": "2k",
"aspect_ratio": "9:16",
"image_with_roles": [
{"url": "https://example.com/person.png", "role": "reference_image"}
],
"audio_urls": ["https://example.com/music.mp3"]
}'
curl https://image2free.com/v1/videos/task-id/remix \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "veo3.1-fast",
"prompt": "保持主体动作,改成雨夜霓虹街道风格",
"aspect_ratio": "16:9",
"resolution": "720p"
}'
{
"code": 200,
"data": [
{ "status": "submitted", "task_id": "j_abc123" }
]
}
用 GET /v1/tasks/{task_id} 查询进度与结果;成功后输出视频 URL,失败自动退款。
| 接口 | 说明 |
|---|---|
| GET /v1/videos/{id} | 返回 {"id":"...","url":"..."} |
| GET /v1/videos/{id}/content | 跳转到视频文件 URL |
| GET /v1/videos/{id}/thumbnail/content | 跳转到视频缩略图;没有缩略图时返回 404 |
| GET /v1/videos/{id}/last-frame/content | 跳转到末帧图片;需要模型返回末帧或请求 return_last_frame |
查询图片/视频异步任务。状态可能为 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": "把这只狗变成水彩画风格",
"size": "1:1",
"quality": "standard",
"image_urls": ["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: "1:1",
quality: "standard",
image_urls: ["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