回调机制概述#
使用回调无需轮询任务状态,系统会把最终结果主动推送到你的服务器。
Content-Type:application/json
工作流程#
1.
{
"model": "runway/gen4-aleph",
"callBackUrl": "https://your-domain.com/api/callback",
"input": {
"prompt": "Turn the scene into a snowy winter day, keep the cartoon fox and the fence",
"video_url": "https://example.com/input-video.mp4"
}
}
2.
{
"code": 200,
"msg": "success",
"data": {
"taskId": "5d2e8b7c41f04a6f9e3b0c7a1d6f2e84"
}
}
3.
任务结束后,你的 callBackUrl 收到回调。
回调请求格式#
回调格式与所有 Market 模型一致。视频地址在 JSON 字符串 data.resultJson 里:JSON.parse(data.resultJson).resultUrls[0]。{
"code": 200,
"msg": "Playground task completed successfully.",
"data": {
"taskId": "5d2e8b7c41f04a6f9e3b0c7a1d6f2e84",
"model": "runway/gen4-aleph",
"state": "success",
"param": "{\"input\":\"{\\\"prompt\\\":\\\"Turn the scene into a snowy winter day, keep the cartoon fox and the fence\\\",\\\"video_url\\\":\\\"https://example.com/input-video.mp4\\\"}\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"model\":\"runway/gen4-aleph\"}",
"resultJson": "{\"resultUrls\":[\"https://tempfile.aiquickdraw.com/p/xxxxxxxx.mp4\"]}",
"createTime": 1791218957000,
"completeTime": 1791219017000,
"updateTime": 1791219017000
}
}
参数说明#
| 参数 | 类型 | 说明 |
|---|
code | integer | 200 成功,501 失败 |
msg | string | 状态消息 |
data.taskId | string | 提交任务时返回的任务 ID |
data.model | string | 任务使用的模型(runway/gen4-aleph) |
data.state | string | success 或 fail |
data.param | string | 创建任务时提交的参数,JSON 字符串 |
data.resultJson | string | 结果,JSON 字符串,如 {"resultUrls":["https://...mp4"]};成功时返回 |
data.failCode | string | 失败码;失败时返回 |
data.failMsg | string | 失败原因;失败时返回 |
data.costTime | integer | 任务耗时(秒) |
data.creditsConsumed | number | 任务消耗的积分 |
data.createTime / data.completeTime / data.updateTime | integer | Unix 毫秒时间戳 |
回调接收示例#
最佳实践#
3.
幂等处理:同一个 taskId 可能收到多次回调。
4.
快速响应 HTTP 200,耗时的业务逻辑异步处理。
故障排查#
替代方案#
获取任务详情
用 taskId 查询任务,结果在 resultJson.resultUrls,与回调一致。