多模型图片与视频生成 API
使用 Fablun 的统一 API Key 为图片与视频任务询价、提交任务并下载结果,所有模型共享同一份美元余额(最低 $5 起充、无月费)。支持 MAGI-2(文生视频 / 首尾帧图生视频,1080P 4–30 秒原生音画)、Seedance 2.5、Veo 3.1、Kling 4.0、Nano Banana 2.1、GPT Image 2 与 FLUX 3。
1. 准备 API Key 与余额
在 Fablun 控制台 创建 API Key · $5 起充余额(无月费) · FABLUN_API_KEY
统一 /api/v3/generations 公开模型目录与规格
以下所有模型共用同一个 API Key 与同一份美元余额(最低 $5 起充、无月费)。在 POST /api/v3/generations 中传入对应 model 标识即可调用。
2. 查询目录与实时报价
BASE='https://fablun.com/api/v3'
curl -fsS "$BASE/catalog/models?display_currency=USD" \
-H "Authorization: Bearer $FABLUN_API_KEY"
curl -fsS "$BASE/generations/quote?model=magi-2&mode=image-to-video&resolution=1080P&duration=5&aspect_ratio=16:9" \
-H "Authorization: Bearer $FABLUN_API_KEY"
3. 提交文生视频任务(MAGI-2 1080P 原生音画)
发送 model: "magi-2",支持 1080P、4–30 秒与 6 种画幅($0.08/秒)。网络重试时复用同一个 Idempotency-Key 避免重复扣费。
BASE='https://fablun.com/api/v3'
curl -fsS "$BASE/generations" \
-H "Authorization: Bearer $FABLUN_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"model": "magi-2",
"mode": "text-to-video",
"prompt": "Rain-slicked Tokyo alley at dusk, slow dolly forward, neon reflections and distant thunder",
"resolution": "1080P",
"duration": 5,
"aspect_ratio": "16:9"
}'
4. 提交图生视频任务(MAGI-2 首帧 / 首尾帧)
传入公开 HTTPS image_url(或 image_base64)即可自动路由至 MAGI-2 图生视频,还支持可选 last_image_url(或 last_image_base64)控制尾帧。支持 16:9 / 9:16 / 1:1 / 4:3 / 3:4,4–30 秒 1080P 原生音画。
BASE='https://fablun.com/api/v3'
curl -fsS "$BASE/generations" \
-H "Authorization: Bearer $FABLUN_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"model": "magi-2",
"mode": "image-to-video",
"prompt": "Slow cinematic camera push-in, gentle breeze moving fabric, warm ambient soundscape",
"image_url": "https://example.com/start-frame.jpg",
"resolution": "1080P",
"duration": 5,
"aspect_ratio": "16:9"
}'
5. Python 完整示例(查询状态并下载 MP4)
import os, time, uuid, requests
BASE = "https://fablun.com/api/v3"
HEADERS = {"Authorization": f"Bearer {os.environ['FABLUN_API_KEY']}"}
job = requests.post(
f"{BASE}/generations",
headers={**HEADERS, "Idempotency-Key": str(uuid.uuid4())},
json={
"model": "magi-2",
"mode": "image-to-video",
"prompt": "Smooth camera orbit with realistic ambient sound",
"image_url": "https://example.com/start-frame.jpg",
"resolution": "1080P",
"duration": 4,
"aspect_ratio": "16:9",
},
timeout=30,
).json()
while job["status"] in ("queued", "running"):
time.sleep(3)
job = requests.get(f"{BASE}/generations/{job['id']}", headers=HEADERS, timeout=30).json()
assert job["status"] == "succeeded", job.get("error")
video = requests.get(f"{BASE}/generations/{job['id']}/media", headers=HEADERS, timeout=120)
open("magi2_output.mp4", "wb").write(video.content)
6. 文生图示例(Nano Banana 2.1 / GPT Image 2 / FLUX 3)
BASE='https://fablun.com/api/v3'
curl -fsS "$BASE/generations" \
-H "Authorization: Bearer $FABLUN_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"model":"nano-banana-2.1","prompt":"A ceramic espresso cup on a warm oak table","resolution":"1k","aspect_ratio":"1:1"}'
H3 Pro 参考生视频与替换 API
POSThttps://fablun.com/api/v3/contents/generations/tasks
使用 Fablun 统一 API Key 调用 h3-pro 参考生视频与视频替换能力,复用同一个任务接口与账户余额。通过 reference_mode 支持三种语义场景(底层自动路由到最优推理引擎):object_swap(兼容 preserve_scene)用于原场景保真物品替换;character_swap 用于视频人物/角色全替换(自动锁定原镜头运动与场景);省略或设为 standard 用于多图/多视频自由参考生成。
可在 Fablun 控制台 创建具有 h3-pro 权限的 API Key,按账号余额计费;失败、取消或超时自动 100% 退还预扣额度,成品链接自完成起有效 1 小时。
场景模式与路由对比(reference_mode)
请求参数与 content[] 角色说明
示例 1:自由参考生视频(standard / 省略 reference_mode)
不传 reference_mode 即走自由参考生视频,支持单图、多图及图+视频组合创作,并在提示词中使用 <Picture 1>、<Video 1> 指代对应素材。
curl -sS -X POST "https://fablun.com/api/v3/contents/generations/tasks" \
-H "Authorization: Bearer $FABLUN_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"model": "h3-pro",
"resolution": "480p",
"duration": 5,
"ratio": "16:9",
"generate_audio": true,
"content": [
{
"type": "text",
"text": "Slow orbital shot of <Picture 1> bathed in warm morning sunlight with subtle ambient sound."
},
{
"type": "image_url",
"image_url": {"url": "https://fablun.com/assets/h3-pro-generated-Cdrx6wmz.webp"},
"role": "reference_image"
}
]
}'
示例 2:物品替换(reference_mode="object_swap")
传入 "reference_mode": "object_swap"(兼容旧值 "preserve_scene")与 1 个源视频 + 1–4 张物品图,像素级锁定原镜头与背景;提示词可省略。
curl -sS -X POST "https://fablun.com/api/v3/contents/generations/tasks" \
-H "Authorization: Bearer $FABLUN_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"model": "h3-pro",
"reference_mode": "object_swap",
"reference_target": "foreground object",
"resolution": "480p",
"duration": 5,
"ratio": "9:16",
"generate_audio": false,
"content": [
{
"type": "video_url",
"video_url": {"url": "https://fablun.com/assets/model-samples/pro-p01-v1.mp4"},
"role": "reference_video"
},
{
"type": "image_url",
"image_url": {"url": "https://fablun.com/assets/h3-pro-generated-Cdrx6wmz.webp"},
"role": "reference_image"
}
]
}'
示例 3:人物/角色替换(reference_mode="character_swap")
传入 "reference_mode": "character_swap" 与 1 个源视频 + 1–4 张目标人物/角色图;可留空提示词由平台自动补全,也可附加细节说明。
curl -sS -X POST "https://fablun.com/api/v3/contents/generations/tasks" \
-H "Authorization: Bearer $FABLUN_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"model": "h3-pro",
"reference_mode": "character_swap",
"resolution": "480p",
"duration": 5,
"ratio": "9:16",
"generate_audio": false,
"content": [
{
"type": "video_url",
"video_url": {"url": "https://fablun.com/assets/model-samples/pro-p01-v1.mp4"},
"role": "reference_video"
},
{
"type": "image_url",
"image_url": {"url": "https://fablun.com/assets/h3-pro-generated-Cdrx6wmz.webp"},
"role": "reference_image"
}
]
}'
示例 4:轮询结果、响应字段与取消任务
成功响应会返回 reference_mode、frames、actual_video_duration_seconds、可直接下载的 content.video_url,以及 GPU 实际耗时遥测 telemetry。若使用原生 Python urllib 请求且遇到网关拦截(1010),请在请求头中显式设置标准 User-Agent(例如 Fablun-Client/1.0)。
# Query task status & result
curl -sS "https://fablun.com/api/v3/contents/generations/tasks/cgt-xxxxxxxxxxxxxxxx" \
-H "Authorization: Bearer $FABLUN_API_KEY"
# Cancel queued/running task
curl -sS -X DELETE "https://fablun.com/api/v3/contents/generations/tasks/cgt-xxxxxxxxxxxxxxxx" \
-H "Authorization: Bearer $FABLUN_API_KEY"
# Sample succeeded response
{
"id": "cgt-89481aa39d5442c3a68ddfc4972e722d",
"model": "h3-pro",
"status": "succeeded",
"reference_mode": "character_swap",
"resolution": "480p",
"duration": 5,
"ratio": "9:16",
"frames": 124,
"actual_video_duration_seconds": 5.166666666666667,
"content": {
"video_url": "https://fablun.com/media/vid_89481aa39d5442c3a68ddfc4972e722d.mp4?expires=...&signature=..."
},
"telemetry": {
"gpu_seconds": 96.329,
"cold_start_ms": 9086,
"vram_peak_mb": 45545
}
}
常见错误码与结算说明
422 InvalidParameter:模型非 h3-pro、reference_mode 非法、混用 first_frame/last_frame、standard 缺少提示词,或在替换模式下缺少 reference_video / reference_image。409 Conflict:同一 Idempotency-Key 对应了不同的请求参数(省略 reference_mode 与显式传入 "standard" 共享同一规范化指纹)。- 参考生视频与替换任务走独立无服务器 GPU 管道,不进入常规队列;失败、取消(
DELETE)或超时均全额退还预扣金额。