图片输入
H3 视频任务 API · /api/v3
H3 Image 参考图编辑
POST /api/v3/images/generations
在同一个 JSON 请求的 image 数组中传入 1 或 2 张参考图。按数组顺序在提示词中使用 @Picture1、@Picture2。每项支持公网 HTTPS URL 或 PNG、JPEG、WebP 的 Base64 data URL。n: 1 表示输出 1 张图。
单图的 image 字段
{
"image": [
"data:image/png;base64,IMAGE_1_BASE64"
]
}双图的 image 字段
{
"image": [
"data:image/png;base64,IMAGE_1_BASE64",
"data:image/png;base64,IMAGE_2_BASE64"
]
}运行双图示例前,在当前目录放置 reference-1.png 和 reference-2.png,并设置 FABLUN_API_KEY 和 FABLUN_OPERATION_KEY。同一个任务重试时复用操作键。
双图 · Python
import json, os, time, urllib.request
import base64
from pathlib import Path
BASE = "https://fablun.com/api/v3"
headers = {"Authorization": "Bearer " + os.environ["FABLUN_API_KEY"],
"Content-Type": "application/json",
"Idempotency-Key": os.environ["FABLUN_OPERATION_KEY"]}
payload = json.loads('''{
"model": "h3-image",
"prompt": "Keep the sailboat and composition from @Picture1. Use the sail color from @Picture2.",
"size": "1k-square",
"n": 1,
"output_format": "png",
"image": [
"data:image/png;base64,IMAGE_1_BASE64",
"data:image/png;base64,IMAGE_2_BASE64"
]
}''')
payload["image"] = [
"data:image/png;base64," + base64.b64encode(Path(name).read_bytes()).decode("ascii")
for name in ["reference-1.png","reference-2.png"]
]
request = urllib.request.Request(BASE + "/images/generations",
data=json.dumps(payload).encode(), headers=headers, method="POST")
with urllib.request.urlopen(request, timeout=60) as response:
task = json.load(response)
print("Task ID:", task["id"], flush=True)
deadline = time.monotonic() + 1800
while time.monotonic() < deadline:
request = urllib.request.Request(BASE + "/images/tasks/" + task["id"], headers=headers)
with urllib.request.urlopen(request, timeout=30) as response:
result = json.load(response)
if result["status"] == "succeeded":
print("Image URL:", result["image_url"])
break
if result["status"] in ("failed", "expired", "cancelled"):
raise RuntimeError(result.get("error") or result["status"])
time.sleep(2)
else:
raise TimeoutError("Continue querying the same Task ID; do not create a new task.")双图 · cURL
python3 - <<'PY' | curl --fail-with-body 'https://fablun.com/api/v3/images/generations' \
-H "Authorization: Bearer $FABLUN_API_KEY" \
-H "Idempotency-Key: ${FABLUN_OPERATION_KEY:?Set a unique key for this operation}" \
-H 'Content-Type: application/json' \
--data-binary @-
import base64, json
from pathlib import Path
payload = json.loads('''{
"model": "h3-image",
"prompt": "Keep the sailboat and composition from @Picture1. Use the sail color from @Picture2.",
"size": "1k-square",
"n": 1,
"output_format": "png",
"image": [
"data:image/png;base64,IMAGE_1_BASE64",
"data:image/png;base64,IMAGE_2_BASE64"
]
}''')
payload["image"] = [
"data:image/png;base64," + base64.b64encode(Path(name).read_bytes()).decode("ascii")
for name in ["reference-1.png","reference-2.png"]
]
print(json.dumps(payload))
PY创建成功返回 HTTP 202 和任务 id。查询 GET /api/v3/images/tasks/{id},任务成功后读取 image_url。
任务状态回调
创建图片任务时可填写 callback_url,使用你自己的公网 HTTPS 接收地址。
"callback_url": "https://YOUR_HOST/webhooks/fablun"平台推送 queued、running 和终态。同一任务的事件共享任务 ID,事件重试保留 X-Fablun-Event-ID。成功时读取 image_url,也可继续通过任务查询获取状态。
沿用视频的回调密钥和验签规则。用 X-Fablun-Timestamp 原文、一个点号及原始请求体计算 HMAC-SHA256,与 X-Fablun-Signature 比较。验签后按事件 ID 去重并返回 HTTP 2xx。中间状态尝试 1 次,终态最多 3 次。
一次请求传入图片
主接口使用 content[].image_url.url:支持公网图片 URL 或完整 Base64 data URL。本地文件由 SDK 读取并编码后随提示词一次提交。
| 输入 | 填写方式 |
|---|---|
| 图片 URL | https://YOUR_IMAGE_HOST/first-frame.jpg |
| Base64 | data:image/jpeg;base64,BASE64_DATA |
| 本地图片 | 切换本地文件示例,Python 自动读取 first-frame.jpg。 |
图生视频示例
import os, time, uuid
from volcenginesdkarkruntime import Ark
client = Ark(
api_key=os.environ["ARK_API_KEY"],
base_url="https://fablun.com/api/v3",
)
request_key = str(uuid.uuid4()) # 仅新任务生成;网络重试改用已保存的原值。
print("Idempotency-Key:", request_key)
task = client.content_generation.tasks.create(
model="h3-pro",
content=[
{"type":"text","text":"人物自然地转头看向镜头,微风吹动头发,镜头缓慢推进。"},
{"type":"image_url","image_url":{"url":"https://YOUR_IMAGE_HOST/first-frame.jpg"},"role":"first_frame"}
],
resolution="480p", duration=5, ratio="16:9",
extra_headers={"Idempotency-Key": request_key},
)
print("task_id:", task.id) # 保存 ID,网络中断后继续查询原任务。
deadline = time.monotonic() + 1800
while time.monotonic() < deadline:
result = client.content_generation.tasks.get(task_id=task.id)
if result.status == "succeeded":
print(result.content.video_url)
break
if result.status in ("failed", "expired", "cancelled"):
raise RuntimeError(result.error or result.status)
time.sleep(2)
else:
raise TimeoutError(f"等待结束,请继续查询原任务:{task.id}")切换到“图生视频”,可选择 URL、Base64 或本地文件。
图片要求
单帧 PNG、JPEG、WebP,原始文件最大 8 MiB;单边 32~8192 像素,总像素不超过 16 × 1024²。URL 使用公网 HTTP(S) 的 80 / 443 端口;H3 Pro · 5 秒支持首帧与尾帧。
首尾帧视频
H3 Pro · 5 秒支持首尾帧;480p / 720p 均支持 1:1、3:4、4:3、16:9、9:16。每种 role 仅一张,last_frame 必须与 first_frame 配对。按一条视频计费,取消、审核和完成回调沿用普通任务流程。return_last_frame 是输出末帧选项,尚未开放。
{
"model": "h3-pro",
"content": [
{
"type": "text",
"text": "A red ball rolls from left to right."
},
{
"type": "image_url",
"image_url": {
"url": "https://YOUR_IMAGE_HOST/first-frame.jpg"
},
"role": "first_frame"
},
{
"type": "image_url",
"image_url": {
"url": "https://YOUR_IMAGE_HOST/last-frame.jpg"
},
"role": "last_frame"
}
],
"resolution": "720p",
"duration": 5,
"ratio": "16:9",
"generate_audio": true
}可选视频压缩
compress:boolean,默认 false。传 true 后在北京 CPU 交付阶段压缩,保留尺寸、帧率和音轨;不另收生成费用。未节省至少 5% 或编码失败时返回原片,并通过 compression.applied / reason 说明。结果完成后沿用普通审核、下载有效期和签名回调。
{
"model": "h3-pro",
"content": [
{
"type": "text",
"text": "A cat walks through a garden."
}
],
"resolution": "720p",
"compress": true
}