素材生成接口
提交生成任务(图片、改图、音效、音乐、视频、3D、配音、序列帧动画),排队执行后取回结果文件。任务是异步的:提交后拿到任务编号,再查询状态。用你的密钥登录用户页可以看到全部记录和用量。
鉴权
所有接口(除 /api/health)都要带密钥:
Authorization: Bearer tk_xxxxxxxx
接口根地址:
快速开始
BASE=
KEY=tk_xxxxxxxx
# 1. 提交任务
curl -s -X POST $BASE/api/tasks -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{
"type": "image", "title": "部落营地",
"params": {"prompt": "卡通风格部落营地,篝火与帐篷", "name": "camp", "target_size": "1280x720", "aspect_ratio": "16:9"}
}'
# => {"id": "T00012", "status": "queued"}
# 2. 查询(每 10–30 秒一次即可;视频通常几分钟)
curl -s $BASE/api/tasks/T00012 -H "Authorization: Bearer $KEY"
# status=done 时,file_urls 是结果文件地址(下载同样要带 Authorization),result.previewUrl 是上游公开预览地址(图片有)
# 3. 下载
curl -s -o camp.png -H "Authorization: Bearer $KEY" "$BASE/files/assets/image/k1_camp_20261124050036.png"
接口
| 方法与路径 | 说明 |
|---|---|
| POST /api/tasks | 提交任务。请求体 {"type", "title"(可选), "params"},返回 {"id","status"} |
| GET /api/tasks/{id} | 任务详情:status、params、result、files、file_urls、credits、error、steps、children(重做出的新任务) |
| GET /api/tasks | 任务列表,倒序。查询参数 status type limit(≤500) offset |
| POST /api/tasks/{id}/redo | 不满意重做:沿用原参数生成新任务,请求体 {"params": {...}} 里的字段会覆盖原参数(如改 prompt)。返回新任务编号 |
| POST /api/tasks/{id}/cancel | 取消排队中的任务(已开始的无法取消) |
| POST /api/uploads?filename=x.png | 上传参考素材,请求体为文件原始字节(≤30MB,图片/视频/音频)。返回 {"path"},可直接用在 params 的文件参数里 |
| GET /files/{path} | 下载自己的结果或上传文件;加 ?download=1 以附件形式下载 |
| GET /api/me | 密钥名称、各状态任务数、已记录积分 |
| GET /api/health | 服务是否在线(无需密钥) |
任务状态
queued 排队中 → running 生成中 → done 完成。异常结束为 failed(上游明确失败,看 error)或 unknown(超时或服务重启,无法确定是否已执行,先查询再决定是否重做,避免重复扣费);canceled 为已取消。
任务类型与参数
| type | 必填 | 常用可选 |
|---|---|---|
| image | prompt, name, target_size(如 "1280x720") | aspect_ratio, resolution(0.5K/1K/2K/4K), transparent, reference_images(≤14), quality, seed, model |
| image_batch | images(数组,每项同 image) | |
| edit_image | image, prompt, name, target_size | reference_images, aspect_ratio, resolution |
| sfx | text | duration_seconds(≤120), loop, output_name |
| sfx_batch | sounds(数组 {name,text,duration,loop}) | |
| music | prompt | customMode, style, title, instrumental, model |
| video | mode, duration(4–10 整数秒) | prompt, images, videos, audios, resolution(480p/720p), ratio, generate_audio |
| 3d | prompt 或 images | quality_tier(fast/balanced/high_quality), rig(true 则生成后绑骨骼), subject_type |
| voice_audition | character_name, character_description, audition_line(≥100 字) | candidate_count(1–3) |
| dialogue | inputs(数组 {character_name,text}) | output_name, stability |
| sprite | sprite, anim,以及 source_image 或 design_prompt,以及 action 或 video_path | duration(默认 4), resolution, fps(默认 12), target_height(默认 256), loop, style_refs |
video.mode
text_to_video / first_frame / first_last_frame / multi_modal_reference。图片写法 "images": [{"url": "...", "role": "first_frame"}]。
sprite(序列帧动画)
流程:设定图 → 视频 → 抠绿幕、拆帧、打包,输出 spritesheet.png、spritesheet.json、frames_preview.webp。设定图要求侧视朝右、纯绿背景(#00FF00)、居中、四肢完整;design_prompt 不含“绿”字时会自动补上。action 只写动作,不描述外观。结果里的 green_residual_pct 偏高时建议换更干净的设定图。
文件参数怎么填
image、reference_images、images、source_image、style_refs、videos、audios 等文件参数只接受:
data:image/png;base64,...形式的 data URL;- http(s) 地址(是否支持取决于上游工具:
edit_image.image支持;reference_images不支持,请用 data URL 或上传;拿不准时先上传再用路径); - 你自己生成或上传过的文件路径,如
assets/image/k1_camp_xxx.png、assets/uploads/k1/xxx.png。
video_path 只接受你自己的文件路径。name / output_name 会自动加上 k{编号}_ 前缀;名称类参数不能包含 / \ ..。
限制
- 视频(含 sprite 的视频步骤)只开放 Seedance 2.0,时长必须显式给出且不超过 10 秒;超出、使用 2.5/wan,或上游判定需人工确认(预计积分过高)的任务会被拒绝或直接失败。
voice_confirm(确认角色音色)不开放;dialogue只能使用已定音的角色。- 视频同一时间只能跑 1 个(平台按账号限制),其余排队;图片等轻量任务最多并发 4 个。
- 积分:只有视频类任务上游会返回实际扣除的积分,记录在
credits;其他类型为null。