提交用户生图(视频)任务
用户自行选择模型并传入提示词,可选传入参考图,提交生图或生视频任务。生图支持 Runware.ai(type_api=1)和 TensorArt(type_api=2);生视频支持 TensorArt(type_api=2)和 WaveSpeed.ai(type_api=3)。该接口不依赖聊天记录。
请求URL:
/submitGenerateMedia
请求方式:
- POST
请求格式:
- 不上传文件:
application/json - 使用
image上传参考图:multipart/form-data
header:
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| Authorization | 是 | string | 授权Token,格式:Bearer {token} |
参数:
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| appId | 是 | string | App唯一标识 |
| udid | 是 | string | 唯一设备ID |
| type | 是 | uint8 | 生成类型:1-生图;2-生视频;用于匹配模型配置 |
| modelId | 否 | uint | 模型ID,从 /getGenerateModelList 获取;生图必填,生视频未传或传0时默认使用模型30 |
| templateId | 否 | uint | 生成模板ID,从 /getGenerateTemplateList 获取;传入后使用模板的正面提示词 |
| prompt | 否 | string | 自定义正向提示词,去除首尾空格后长度为1~4000字符;未传templateId时必填 |
| negativePrompt | 否 | string | 负向提示词,最大4000字符;未传时使用模型配置中的负向提示词 |
| ratio | 否 | string | 图片/视频比例,支持 1:1、3:4、4:3、9:16、16:9;传入后优先于width/height |
| image | 否 | File | 参考图片文件,仅支持JPEG、PNG、WEBP,最大20MB;传文件时请求格式必须为multipart/form-data |
| referenceImage | 否 | string | 公开可访问的HTTP/HTTPS参考图完整地址,最大20MB |
| referenceImageResourceId | 否 | string | 已上传到TensorArt的图片资源ID;仅 type_api=2 模型支持 |
| width | 否 | uint | 兼容参数,自定义宽度;ratio未传时生效,最大1024 |
| height | 否 | uint | 兼容参数,自定义高度;ratio未传时生效,最大1024 |
| steps | 否 | uint | 生图采样步数,范围0~60;不传或传0时使用模型数据库配置,超过60时按60执行 |
| cfgScale | 否 | float | 生图提示词引导系数,范围0.1~30;不传或传0时使用模型数据库配置 |
| quantity | 否 | uint | 生图数量,范围1~4,默认1;生视频不支持大于1 |
| seed | 否 | int64 | 随机种子;不传或传0时随机生成 |
| duration | 否 | uint | 视频时长,单位秒,最大30;仅生视频有效;不传时使用模型默认值 |
| fps | 否 | uint | 视频帧率,最大60;仅生视频有效;不传时使用模型默认值 |
image、referenceImage和referenceImageResourceId只能传其中一个,也可以都不传。TensorArt 模型会将image或referenceImage上传为 TensorArt 资源;Runware 和 WaveSpeed 模型会将图片转存为可公开访问的图片 URL。referenceImageResourceId仅支持 TensorArt 模型。
生图任务必须传入 modelId。生视频任务可以省略 modelId 或传 0,后台此时使用默认模型 30;传入非0值时仍使用客户端指定的模型。
传入 templateId 时,后台会校验模板已上架且模板类型与任务 type 一致,并使用模板记录中的 positive_prompt 覆盖请求参数 prompt。测试用户也可以使用 state=2 的测试模板。未传 templateId 时继续使用客户端提交的 prompt。
比例对应尺寸:
| ratio | width | height |
|---|---|---|
| 1:1 | 1024 | 1024 |
| 3:4 | 768 | 1024 |
| 4:3 | 1024 | 768 |
| 9:16 | 576 | 1024 |
| 16:9 | 1024 | 576 |
比例生成的最大边固定为1024。未传 ratio 时兼容原有 width、height:生图宽高必须是512~1024之间的64倍数;生视频宽高必须是64~1024之间的16倍数。ratio、width、height 均未传时使用后台模型配置值。
WaveSpeed视频模型会把比例转换为第三方的 aspect_ratio,输出清晰度使用720p;当前WaveSpeed视频接口不使用 negativePrompt 和 fps 参数。TensorArt视频模型继续使用宽、高、帧率和负向提示词。
文生图请求示例:
{
"appId": "com.example.app",
"udid": "device-uuid",
"type": 1,
"modelId": 58,
"prompt": "A cinematic portrait, soft light",
"negativePrompt": "low quality, blurry",
"ratio": "1:1",
"steps": 30,
"cfgScale": 7.5,
"quantity": 3,
"seed": 123456
}
使用模板请求示例:
{
"appId": "com.example.app",
"udid": "device-uuid",
"type": 1,
"modelId": 58,
"templateId": 1,
"ratio": "1:1",
"quantity": 1
}
使用模板时可以不传 prompt;即使同时传入,后台也以模板的 positive_prompt 为准。
当 quantity 大于1时,后台会创建对应数量的独立任务。若传入正数 seed,第一个任务使用该值,后续任务依次加1;不传或传0时,每个任务均使用随机种子。
Runware参考图生图请求示例:
curl --request POST 'https://domain/api/submitGenerateMedia' \
--header 'Authorization: Bearer {token}' \
--form 'appId=com.example.app' \
--form 'udid=device-uuid' \
--form 'type=1' \
--form 'modelId=60' \
--form 'prompt=Transform the portrait into watercolor style' \
--form 'ratio=1:1' \
--form 'image=@/path/to/reference.png'
当所选模型 typeApi=1 时,后台会将参考图转存为公开 URL,并通过 Runware 的 seedImage 参数提交;转换强度使用模型数据库中的 denoising_strength,无效配置回退为0.8。
Runware模型ID 81(alibaba:wan@2.7-image)使用专用参考图协议:必须上传参考图,后台通过 inputs.referenceImages 提交。该模型不支持 steps、cfgScale、clipSkip、scheduler、strength、seedImage 和 seed,即使客户端传入这些通用参数也不会转发给第三方。
上传参考图生视频请求示例:
curl --request POST 'https://domain/api/submitGenerateMedia' \
--header 'Authorization: Bearer {token}' \
--form 'appId=com.example.app' \
--form 'udid=device-uuid' \
--form 'type=2' \
--form 'modelId=59' \
--form 'prompt=The girl slowly turns her head and smiles' \
--form 'ratio=9:16' \
--form 'duration=3' \
--form 'fps=16' \
--form 'image=@/path/to/reference.png'
上传图片时,除 image 外的字段同样放在multipart表单中。后台校验文件后,会根据所选模型平台上传为 TensorArt 资源或转存到本站对象存储,再创建生图或生视频任务。
参考图URL生视频请求示例:
{
"appId": "com.example.app",
"udid": "device-uuid",
"type": 2,
"modelId": 59,
"prompt": "The girl slowly turns her head and smiles",
"referenceImage": "https://cdn.example.com/reference.jpg",
"ratio": "9:16",
"duration": 3,
"fps": 16
}
使用TensorArt资源ID请求示例:
该方式仅适用于模型列表中 typeApi=2 的模型。
{
"appId": "com.example.app",
"udid": "device-uuid",
"type": 2,
"modelId": 59,
"prompt": "Camera slowly pushes forward",
"referenceImageResourceId": "72f331bd-2916-44b4-b3ab-c3cd8e029283",
"ratio": "16:9"
}
返回示例:
{
"code": 200,
"msg": "SUCCESS",
"data": {
"id": 790110,
"type": 8,
"state": 5,
"path": "",
"reason": "",
"cost": 7,
"startTime": 1785398400,
"elapsedTime": 0,
"quantity": 2,
"totalCost": 14,
"tasks": [
{
"id": 790110,
"type": 8,
"state": 5,
"path": "",
"reason": "",
"cost": 7,
"startTime": 1785398400,
"elapsedTime": 0
},
{
"id": 790111,
"type": 8,
"state": 5,
"path": "",
"reason": "",
"cost": 7,
"startTime": 1785398400,
"elapsedTime": 0
}
]
}
}
返回参数说明:
| 参数名 | 类型 | 说明 |
|---|---|---|
| code | int | 状态码 |
| msg | string | 提示信息 |
| data | struct | 任务数据 |
| - id | uint | 首个任务ID,保留该字段用于兼容原有客户端 |
| - type | uint8 | 主动生成任务类型:8-生图;9-生视频 |
| - state | uint8 | 任务状态:2-失败;5-准备参数;10-等待执行;20-执行中;30-执行成功 |
| - path | string | 生成文件完整地址;任务成功前为空 |
| - reason | string | 失败原因 |
| - cost | uint | 单个任务实际消耗钻石数,已包含适用的VIP折扣 |
| - startTime | int64 | 任务开始时间,Unix秒时间戳 |
| - elapsedTime | uint | 已记录的任务耗时,单位秒 |
| - quantity | uint | 本次创建的任务数量 |
| - totalCost | int | 本次全部任务实际扣除的钻石总数 |
| - tasks | array | 本次创建的全部任务;每项结构与首个任务字段一致 |
处理流程:
- 接口校验用户、模型、平台、比例和参考图片参数;图片模型支持
type_api=1、type_api=2,视频模型支持type_api=2、type_api=3。 - 按模型单价、数量及用户VIP权益计算并一次扣除总钻石数。
- 按
quantity创建独立任务;若上传了image,后台只上传一次并让全部任务复用同一个TensorArt资源ID或公开图片URL。 - 多图任务会分别创建第三方任务,确保每张图片均可独立查询和接收通知;Runware生图同步取得第三方结果,TensorArt和WaveSpeed任务按各自平台方式轮询结果。
- 客户端遍历返回的
tasks,使用各项id调用/getGenerateTaskInfo轮询任务状态。 - 每个任务独立完成并发送SSE;某个任务失败时,仅退还该任务消耗的钻石并回退一次生成次数。
SSE通知:
全部任务记录创建成功后,服务端会立即通过SSE通知用户最新余额,消息 type 为5。多图时 count 为本次所有任务的总消费:
{
"type": 5,
"msg": "The recharge was successful and the balance of gold coins increased by 14",
"data": {
"count": 14,
"balance": 86,
"payBalance": 60,
"freeBalance": 26,
"strengthBalance": 5
}
}
| 参数名 | 类型 | 说明 |
|---|---|---|
| type | int | 消息类型,余额变动固定为5 |
| msg | string | 消息说明 |
| data | struct | 余额数据 |
| - count | int | 本次任务消费钻石数 |
| - balance | int | 当前总钻石余额 |
| - payBalance | int | 当前充值钻石余额 |
| - freeBalance | int | 当前免费钻石余额 |
| - strengthBalance | uint | 当前体力余额 |
每个任务执行完成或失败后,都会分别通过SSE推送任务结果,客户端通过通知中的 taskId 与提交结果的 tasks[].id 对应。任务结果通知格式见用户生图(视频)任务详情。
错误码:
- 510 系统异常
- 670 登录失效
- 730 钻石余额不足
- 800 参数错误
- 900 模型不存在、已下架或类型不匹配