文档 / API 参考 / 上传文件
POST
/v1/files上传文件
上传本地文件并获取一个带签名的 URL。在视频任务的 metadata.content[] 中使用该 URL,例如作为 reference_image。
#请求
以 multipart/form-data 形式发送,并带上 Authorization: Bearer sk-...:
| 字段 | 类型 | 说明 |
|---|---|---|
file | File | 要上传的文件:jpg、jpeg、png、webp、gif(最大 10 MB),mp3、wav(最大 20 MB),mp4、mov、webm(最大 47 MB) |
purpose | string | 可选。会被接受并原样返回,用于兼容 OpenAI SDK |
#示例:cURL
terminalbash
curl https://relaydance.com/v1/files \
-H "Authorization: Bearer $RELAYDANCE_API_KEY" \
-F "[email protected]"#示例:Python
upload.pypython
import requests, os
with open("input.jpg", "rb") as f:
resp = requests.post(
"https://relaydance.com/v1/files",
headers={"Authorization": f"Bearer {os.environ['RELAYDANCE_API_KEY']}"},
files={"file": f},
timeout=300,
)
data = resp.json()
print(data["id"], data["url"])#响应
response.jsonjson
{
"id": "file-0123456789abcdef0123456789abcdef-jpg",
"object": "file",
"bytes": 482113,
"created_at": 1794710000,
"filename": "input.jpg",
"purpose": "user_data",
"status": "processed",
"content_type": "image/jpeg",
"md5": "0123456789abcdef0123456789abcdef",
"url": "https://...",
"source_url": "https://...",
"expires_in": 21600,
"url_expires_at": 1794731600,
"exists": false
}| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 文件标识符 |
url | string | 带签名的 URL,可直接用作参考媒体;有效期为 expires_in 秒(6 小时)。source_url 是同一个链接 |
bytes | integer | 已存文件的大小 |
content_type | string | 从文件识别出的类型 |
exists | boolean | 同一个文件以前传过、这次没有重复存储时为 true |
#获取新链接
GET
/v1/files/{id}返回同一个对象和一个新的 url,有效期重新计 6 小时。只有上传该文件的账号才能取回它。
#错误
| 状态码 | 错误码 | 含义 |
|---|---|---|
401 | invalid_api_key | 缺少 API Key,或 API Key 不存在、已停用、已过期 |
400 | missing_file | 没有名为 file 的 multipart 字段 |
400 | unsupported_file_type | 文件类型不在支持范围内 |
400 | file_type_mismatch | 文件内容与扩展名不符,例如把文本文件命名为 .png |
413 | file_too_large | 超过该类型的大小上限 |
429 | rate_limit_exceeded | 同一账号一小时内上传超过 120 次 |
404 | file_not_found | GET 时该账号下没有这个 id |