Skip to main content
POST
/
api
/
open
/
v2
/
assets
上传工作流资源
curl --request POST \
  --url https://www.chenyu.cn/api/open/v2/assets \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "media_type": "<string>",
  "purpose": "<string>",
  "ttl_hours": 123
}
'
{
  "code": 123,
  "msg": "<string>",
  "data": {
    "asset_id": "<string>",
    "asset_uri": "<string>",
    "url": "<string>",
    "content_url": "<string>",
    "signed_url": "<string>",
    "media_type": "<string>",
    "mime_type": "<string>",
    "size_bytes": 123,
    "purpose": "<string>",
    "persistent": true,
    "expires_at": "<string>",
    "status": "<string>"
  }
}

上传工作流资源

上传图片、视频、音频或文件,生成可在工作流 inputs 中使用的临时资源地址。适用于文件较大、需要复用、或不方便直接暴露公网 URL 的场景。
上传成功后使用返回的 asset_uri 字段值,例如 asset://asset_xxx。提交工作流时可以直接把这个字符串放入 inputs。需要声明素材角色或在提示词里引用素材时,使用 { "uri": "...", "role": "...", "label": "..." } 对象。临时资源默认 48 小时有效。

请求参数

请求类型为 multipart/form-data
file
file
required
要上传的本地文件,单个文件最大 100MB
media_type
string
资源类型。常用值:imagevideoaudiofile。不传时服务端会根据文件类型推断
purpose
string
资源用途。当前对外接口仅支持 temp_input,不传时默认 temp_input
ttl_hours
integer
临时资源有效小时数。不传时默认 48 小时

响应参数

code
integer
响应码,0 表示成功
msg
string
响应信息
data
object
上传后的资源信息

代码示例

import requests

url = "https://www.chenyu.cn/api/open/v2/assets"
headers = {"Authorization": "Bearer your_api_key"}
files = {"file": open("input.png", "rb")}
data = {
    "media_type": "image",
    "purpose": "temp_input"
}

response = requests.post(url, headers=headers, files=files, data=data)
asset_uri = response.json()["data"]["asset_uri"]
print(asset_uri)

响应示例

{
  "code": 0,
  "msg": "上传成功",
  "data": {
    "asset_id": "asset_38d2ff7769fb3b7267039941547e6a78",
    "asset_uri": "asset://asset_38d2ff7769fb3b7267039941547e6a78",
    "url": "https://www.chenyu.team/assets/asset_38d2ff7769fb3b7267039941547e6a78/content",
    "content_url": "https://www.chenyu.team/assets/asset_38d2ff7769fb3b7267039941547e6a78/content",
    "signed_url": "https://www.chenyu.team/assets/asset_38d2ff7769fb3b7267039941547e6a78/content?expires=1781295600&signature=xxxx",
    "media_type": "image",
    "mime_type": "image/png",
    "size_bytes": 102400,
    "purpose": "temp_input",
    "persistent": false,
    "expires_at": "2026-06-16T12:00:00+08:00",
    "status": "confirmed",
    "original_filename": "input.png"
  }
}

在工作流中使用

媒体字段支持三种写法:
{
  "image": "https://example.com/input.png"
}
{
  "image": "data:image/png;base64,iVBORw0KGgo..."
}
{
  "image": "asset://asset_38d2ff7769fb3b7267039941547e6a78"
}
需要声明首帧、尾帧、参考素材角色,或需要在提示词里用 @标签 引用素材时,可以使用对象写法:
{
  "first_frame": {
    "uri": "asset://asset_38d2ff7769fb3b7267039941547e6a78",
    "role": "first_frame",
    "label": "首帧"
  }
}
多素材引用示例:
{
  "generation_category": "reference_to_video",
  "prompt": "@阿九 和 @沈渡 在舞台上跳舞",
  "images": [
    {
      "uri": "asset://asset_person_a",
      "label": "阿九",
      "role": "reference_image"
    },
    {
      "uri": "asset://asset_person_b",
      "label": "沈渡",
      "role": "reference_image"
    }
  ]
}
label 是素材显示名,不需要带 @;提示词里引用时写 @阿九。同一个请求里的 label 不能重复,也兼容 {{阿九}}{{ 阿九 }} 写法。