上传文件
Upload files
purposestringrequired
Value in
"batch"Example
"batch"fileFile uploadrequired
File to upload
Format
binaryExample
"/path/to/abc.jsonl"Response Body
Successful response
TypeScript Definitions
Use the response body type in TypeScript.
codeinteger
Example
20000messagestring
Example
"Ok"statusboolean
Example
truedataobject
curl --request post \
--url https://api.siliconflow.cn/v1/files \
--header 'authorization: Bearer <token>' \
--header 'content-type: multipart/form-data' \
--form purpose=batch \
--form 'file=@files_example'
import requests
url = "https://api.siliconflow.cn/v1/files"
headers = {
"authorization": "Bearer <token>"
}
with open("files_example", "rb") as f:
files = {
"file": ("files_example", f)
}
data = {
"purpose": "batch"
}
response = requests.post(url, headers=headers, data=data, files=files)
print(response.status_code)
print(response.json())
import { readFileSync } from "fs";
import { fetch, FormData, File } from "undici"; // Node 18+ 可直接用,否则需安装 undici
const url = "https://api.siliconflow.cn/v1/files";
const form = new FormData();
form.append("purpose", "batch");
const fileBuffer = readFileSync("files_example");
form.append("file", new File([fileBuffer], "files_example"));
const response = await fetch(url, {
method: "POST",
headers: {
authorization: "Bearer <token>",
// 不需要手动设置 content-type,fetch + FormData 会自动加 boundary
},
body: form,
});
console.log(response.status);
const data = await response.json();
console.log(data);
{
"code": 20000,
"message": "Ok",
"status": true,
"data": {
"id": "file-jkvytbjtow",
"object": "file",
"bytes": 8509,
"createdAt": 1741685396,
"filename": "requests.jsonl",
"purpose": "batch"
}
}{
"code": 20012,
"message": "string",
"data": "string"
}"Invalid token""Forbidden""404 page not found"{
"code": 50505,
"message": "Model service overloaded. Please try again later.",
"data": "string"
}"string"