运行作业
作业对一个或多个已上传的文件运行一个操作。它会立即启动,在后台运行,并报告每个文件的处理结果。
本页内容
操作是作业要做的事,例如 video.compress。GET /v1/operations 列出所有操作,GET /v1/operations/{id} 返回单个操作及其设置 Schema。
curl https://api.filesokay.com/v1/operations/video.compressconst res = await fetch("https://api.filesokay.com/v1/operations/video.compress");
const operation = await res.json();import requests
res = requests.get(
"https://api.filesokay.com/v1/operations/video.compress",
)
operation = res.json()每个操作都会说明它接受什么、如何工作:
| 字段 | 含义 |
|---|---|
input_formats | 它接受的文件扩展名。如果您为某个文件发送的 type 属于该操作的类别(例如 video/mp4),其他扩展名的文件也会被接受。 |
max_files | 单个作业最多接受的输入文件数。 |
limits.max_file_bytes | 输入文件的最大大小,以字节为单位。 |
grouping | separate:每个文件一个任务,各自产出结果。together:所有文件共用一个任务,例如合并。 |
settings_schema | 其设置所遵循的 JSON Schema,包含每项设置的默认值。 |
发送操作、以 ID 指定的输入文件,还可以按需附上操作的设置和您自定义的参考值。同时发送 Idempotency-Key,确保重试绝不会启动第二个作业。
curl -X POST https://api.filesokay.com/v1/jobs \
-H "Authorization: Bearer $FILESOKAY_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"operation": "video.compress",
"inputs": [
{
"file_id": "file_3cf0737aefa34b89b7b4443c9467d60c"
}
],
"settings": {
"method": "target_size",
"target": {
"unit": "percent",
"value": 50
}
},
"client_reference": "lecture-0412"
}'const res = await fetch("https://api.filesokay.com/v1/jobs", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.FILESOKAY_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(),
},
body: JSON.stringify({
operation: "video.compress",
inputs: [
{
file_id: "file_3cf0737aefa34b89b7b4443c9467d60c"
}
],
settings: {
method: "target_size",
target: {
unit: "percent",
value: 50
}
},
client_reference: "lecture-0412"
}),
});
const job = await res.json();import os
import uuid
import requests
res = requests.post(
"https://api.filesokay.com/v1/jobs",
headers={
"Authorization": f"Bearer {os.environ['FILESOKAY_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"operation": "video.compress",
"inputs": [
{
"file_id": "file_3cf0737aefa34b89b7b4443c9467d60c"
}
],
"settings": {
"method": "target_size",
"target": {
"unit": "percent",
"value": 50
}
},
"client_reference": "lecture-0412"
},
)
job = res.json(){
"id": "job_a1c9531eeb00434aba0058796f1ca517",
"operation": "video.compress",
"status": "waiting",
"client_reference": "lecture-0412",
"settings": {
"audio": "keep",
"codec": "same",
"method": "target_size",
"target": {
"unit": "percent",
"value": 50
},
"frame_rate": "original",
"resolution": "auto",
"output_format": "same"
},
"created_at": "2026-12-03T09:23:14Z",
"reserved_credits": 2,
"charged_credits": 0,
"tasks": [
{
"id": "task_3f648f64472b4ea4b88568eea9d4f88c",
"status": "waiting",
"progress": 0,
"reserved_credits": 2,
"inputs": [
{
"file_id": "file_3cf0737aefa34b89b7b4443c9467d60c",
"name": "lecture.mp4"
}
],
"outputs": []
}
]
}settings会按操作的 Schema 进行校验。省略的设置会使用默认值,作业会列出所有设置,并填入默认值。tasks中每个输入对应一个任务,顺序与您的请求一致。reserved_credits是该作业可能产生的最高费用。最终只按实际用量扣除:请参阅积分。
POST /v1/estimates 接受与 POST /v1/jobs 相同的请求体,但不会运行任何内容。它会返回作业的最高费用、您拥有的积分、还差多少积分,以及每个文件将得到怎样的结果。
curl -X POST https://api.filesokay.com/v1/estimates \
-H "Authorization: Bearer $FILESOKAY_KEY" \
-H "Content-Type: application/json" \
-d '{
"operation": "video.compress",
"inputs": [
{
"file_id": "file_3cf0737aefa34b89b7b4443c9467d60c"
}
],
"settings": {
"method": "target_size",
"target": {
"unit": "percent",
"value": 50
}
}
}'const res = await fetch("https://api.filesokay.com/v1/estimates", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.FILESOKAY_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
operation: "video.compress",
inputs: [
{
file_id: "file_3cf0737aefa34b89b7b4443c9467d60c"
}
],
settings: {
method: "target_size",
target: {
unit: "percent",
value: 50
}
}
}),
});
const estimate = await res.json();import os
import requests
res = requests.post(
"https://api.filesokay.com/v1/estimates",
headers={
"Authorization": f"Bearer {os.environ['FILESOKAY_KEY']}",
},
json={
"operation": "video.compress",
"inputs": [
{
"file_id": "file_3cf0737aefa34b89b7b4443c9467d60c"
}
],
"settings": {
"method": "target_size",
"target": {
"unit": "percent",
"value": 50
}
}
},
)
estimate = res.json(){
"available_credits": 1908,
"operation": "video.compress",
"reserved_credits": 2,
"settings": {
"method": "target_size",
"target": {
"unit": "percent",
"value": 50
},
"resolution": "auto",
"codec": "same",
"frame_rate": "original",
"audio": "keep",
"output_format": "same"
},
"shortfall": 0,
"tasks": [
{
"status": "waiting",
"inputs": [
{
"file_id": "file_3cf0737aefa34b89b7b4443c9467d60c",
"name": "lecture.mp4"
}
],
"reserved_credits": 2,
"preview": {
"output": {
"format": "mp4",
"extension": "mp4",
"file_name": "lecture-compressed.mp4"
},
"video": {
"codec": "h264",
"width": 1280,
"height": 720,
"frame_rate": "original",
"hdr": "none"
},
"smallest_bytes": 634179
}
}
]
}| 作业状态 | 含义 |
|---|---|
waiting | 没有任务在运行,且至少有一个任务仍在等待开始。 |
processing | 至少有一个任务正在运行。 |
completed | 除已取消的任务外,所有任务均已完成。 |
partly_failed | 部分任务完成,部分任务失败。 |
failed | 除已取消的任务外,所有任务均失败。 |
cancelled | 在任何任务完成之前即被取消。 |
每个任务都有自己的 status:waiting、processing、completed、failed、cancelled 或 skipped。正在运行的任务会显示 progress,范围为 0 到 100。失败或被跳过的任务会给出 reason。
一个作业可以对多个文件运行同一个操作,数量上限为该操作的 max_files。在 separate 分组方式下,每个文件都是独立的任务:一个文件失败不会影响其他文件,失败的文件也不扣费。
无法使用的文件会被跳过并注明原因,其余文件照常运行。被跳过的文件不产生任何费用。跳过原因如下:
| 原因 | 含义 |
|---|---|
not_found | 没有已上传的文件使用此 ID。 |
not_ready | 该文件的上传尚未完成。 |
refused | 检测拒绝了该文件。 |
check_failed | 由于我们这边的问题,检测失败。 |
other_operation | 该文件是为另一个操作上传的。 |
file_in_use | 另一个作业正在使用该文件。 |
repeated | 该文件在此作业中出现了两次。 |
如果某个文件在当前设置下不会发生任何变化,操作也可以跳过它,例如视频已经小于目标大小。当没有任何文件会运行时,作业不会启动:请求会被拒绝并返回 nothing_to_run,并附上每个文件的原因。而采用 together 分组方式的操作会用所有文件生成一个结果,因此它会改为以 files_unusable 拒绝整个作业。
client_reference 用于存放您为作业指定的自有 ID,例如订单号,最长 255 个字符。它会随作业及每条 Webhook 消息一起返回,您也可以通过 GET /v1/jobs?client_reference=… 按它查找作业。它不必唯一。
POST /v1/jobs/{id}/cancel 会停止仍在等待或运行的任务。尚未开始的任务不产生费用;已开始的任务按已运行的时间计费。取消已结束的作业不会有任何变化。
curl -X POST https://api.filesokay.com/v1/jobs/job_a1c9531eeb00434aba0058796f1ca517/cancel \
-H "Authorization: Bearer $FILESOKAY_KEY"const res = await fetch("https://api.filesokay.com/v1/jobs/job_a1c9531eeb00434aba0058796f1ca517/cancel", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.FILESOKAY_KEY}`,
},
});
const job = await res.json();import os
import requests
res = requests.post(
"https://api.filesokay.com/v1/jobs/job_a1c9531eeb00434aba0058796f1ca517/cancel",
headers={
"Authorization": f"Bearer {os.environ['FILESOKAY_KEY']}",
},
)
job = res.json()