上传工作流资源
curl --request POST \
--url https://www.chenyu.cn/api/open/v2/assets \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form file='@example-file' \
--form purpose=temp_input \
--form ttl_hours=48import requests
url = "https://www.chenyu.cn/api/open/v2/assets"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = {
"purpose": "temp_input",
"ttl_hours": "48"
}
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
form.append('purpose', 'temp_input');
form.append('ttl_hours', '48');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://www.chenyu.cn/api/open/v2/assets', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.chenyu.cn/api/open/v2/assets",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\ntemp_input\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"ttl_hours\"\r\n\r\n48\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://www.chenyu.cn/api/open/v2/assets"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\ntemp_input\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"ttl_hours\"\r\n\r\n48\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://www.chenyu.cn/api/open/v2/assets")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\ntemp_input\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"ttl_hours\"\r\n\r\n48\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.chenyu.cn/api/open/v2/assets")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\ntemp_input\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"ttl_hours\"\r\n\r\n48\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"code": 123,
"msg": "<string>",
"data": {
"id": "<string>",
"asset_id": "<string>",
"asset_uri": "asset://asset_38d2ff7769fb3b7267039941547e6a78",
"url": "<string>",
"content_url": "<string>",
"signed_url": "<string>",
"media_type": "<string>",
"mime_type": "<string>",
"size_bytes": 123,
"purpose": "<string>",
"persistent": true,
"expires_at": "2023-11-07T05:31:56Z",
"status": "<string>",
"original_filename": "<string>"
}
}资源管理
上传工作流资源
上传用于工作流输入的临时资源
POST
/
api
/
open
/
v2
/
assets
上传工作流资源
curl --request POST \
--url https://www.chenyu.cn/api/open/v2/assets \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form file='@example-file' \
--form purpose=temp_input \
--form ttl_hours=48import requests
url = "https://www.chenyu.cn/api/open/v2/assets"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = {
"purpose": "temp_input",
"ttl_hours": "48"
}
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
form.append('purpose', 'temp_input');
form.append('ttl_hours', '48');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://www.chenyu.cn/api/open/v2/assets', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.chenyu.cn/api/open/v2/assets",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\ntemp_input\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"ttl_hours\"\r\n\r\n48\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://www.chenyu.cn/api/open/v2/assets"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\ntemp_input\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"ttl_hours\"\r\n\r\n48\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://www.chenyu.cn/api/open/v2/assets")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\ntemp_input\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"ttl_hours\"\r\n\r\n48\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.chenyu.cn/api/open/v2/assets")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\ntemp_input\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"ttl_hours\"\r\n\r\n48\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"code": 123,
"msg": "<string>",
"data": {
"id": "<string>",
"asset_id": "<string>",
"asset_uri": "asset://asset_38d2ff7769fb3b7267039941547e6a78",
"url": "<string>",
"content_url": "<string>",
"signed_url": "<string>",
"media_type": "<string>",
"mime_type": "<string>",
"size_bytes": 123,
"purpose": "<string>",
"persistent": true,
"expires_at": "2023-11-07T05:31:56Z",
"status": "<string>",
"original_filename": "<string>"
}
}上传工作流资源
上传图片、视频、音频或文件,生成可在工作流inputs 中使用的临时资源地址。适用于文件较大、需要复用、或不方便直接暴露公网 URL 的场景。
上传成功后使用返回的
asset_uri 字段值,例如 asset://asset_xxx。提交工作流时可以直接把这个字符串放入 inputs。需要声明素材角色或在提示词里引用素材时,使用 { "uri": "...", "role": "...", "label": "..." } 对象。临时资源默认 48 小时有效。请求参数
请求类型为multipart/form-data。
file
required
要上传的本地文件,单个文件最大 100MB
string
资源类型。常用值:
image、video、audio、file。不传时服务端会根据文件类型推断string
资源用途。当前对外接口仅支持
temp_input,不传时默认 temp_inputinteger
临时资源有效小时数。不传时默认 48 小时
响应参数
integer
响应码,
0 表示成功string
响应信息
object
上传后的资源信息
Show data
Show data
string
资源 ID,可用于查询资源状态和访问地址
string
资源引用地址,提交工作流
inputs 时优先使用,例如 asset://asset_xxxstring
资源访问地址
string
资源内容访问地址,与
url 含义一致string
带签名的临时访问地址
string
资源类型,例如
imagestring
MIME 类型,例如
image/pnginteger
文件大小,单位字节
string
资源用途,当前为
temp_inputboolean
是否为长期资源。临时输入资源一般为
falsestring
临时资源过期时间
string
资源状态。可用状态通常为
confirmed代码示例
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)
const axios = require('axios');
const fs = require('fs');
const FormData = require('form-data');
const form = new FormData();
form.append('file', fs.createReadStream('input.png'));
form.append('media_type', 'image');
form.append('purpose', 'temp_input');
axios.post('https://www.chenyu.cn/api/open/v2/assets', form, {
headers: {
Authorization: 'Bearer your_api_key',
...form.getHeaders()
}
}).then((response) => {
console.log(response.data.data.asset_uri);
});
curl -X POST "https://www.chenyu.cn/api/open/v2/assets" \
-H "Authorization: Bearer your_api_key" \
-F "file=@input.png" \
-F "media_type=image" \
-F "purpose=temp_input"
响应示例
{
"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"
}
}
在工作流中使用
先查询 工作流详情。当editable_parameter_manifest[].value_type 表示图片、视频、音频或文件输入时,在 inputs 中使用该条目的 name 作为 key,参数值支持三种资源字符串:
{
"n10_image": "https://example.com/input.png"
}
{
"n10_image": "data:image/png;base64,iVBORw0KGgo..."
}
{
"n10_image": "asset://asset_38d2ff7769fb3b7267039941547e6a78"
}
asset_uri。参数名、必填规则和文件类型均以当前工作流详情返回的 manifest 为准,完整说明见 editable_parameter_manifest 输入参数清单。Authorizations
API Key,格式:Bearer your_api_key
Body
multipart/form-data
⌘I