Quickstart
Compress a video with the FilesOkay API in five steps. Each step shows the call in curl, Node.js and Python, and the answer it gets back.
On this page
- A FilesOkay Workspace with an active subscription. Limits and credits explains why.
- For the Node.js steps, Node.js 20 or later. For the Python steps, Python 3.9 or later and the
requestspackage. - A video to compress. The examples call it
lecture.mp4.
The steps build one script. Start it with this, which reads your key from the FILESOKAY_KEY environment variable:
export FILESOKAY_KEY="filesokay_…"// quickstart.mjs: run it with `node quickstart.mjs` (Node.js 20 or later).
import fs from "node:fs";
import https from "node:https";
import { Readable } from "node:stream";
import { pipeline } from "node:stream/promises";
const API = "https://api.filesokay.com/v1";
// Calls the API, and throws its error code when it refuses.
async function api(method, path, body, headers = {}) {
const res = await fetch(API + path, {
method,
headers: {
Authorization: `Bearer ${process.env.FILESOKAY_KEY}`,
"Content-Type": "application/json",
...headers,
},
body: body && JSON.stringify(body),
});
const data = res.status === 204 ? null : await res.json();
if (!res.ok) throw new Error(`${data.code}: ${data.detail}`);
return data;
}# quickstart.py: run it with `python quickstart.py` (Python 3.9 or later, with `pip install requests`).
import os
import time
import uuid
import requests
API = "https://api.filesokay.com/v1"
def api(method, path, body=None, headers=None):
"""Calls the API, and raises its error code when it refuses."""
res = requests.request(
method,
API + path,
json=body,
headers={"Authorization": f"Bearer {os.environ['FILESOKAY_KEY']}", **(headers or {})},
)
data = res.json() if res.content else None
if not res.ok:
raise RuntimeError(f"{data['code']}: {data['detail']}")
return dataIn your Workspace, open Settings, then API keys, and select Create API key. Name the key and confirm it’s you. The key is shown once: copy it into FILESOKAY_KEY.
Start the upload with the file’s name and size. Send the file to the link you get back, then complete the upload, which checks the file.
# Start the upload with the file's name and size in bytes.
curl https://api.filesokay.com/v1/uploads \
-H "Authorization: Bearer $FILESOKAY_KEY" \
-H "Content-Type: application/json" \
-d '{
"operation": "video.compress",
"files": [{ "name": "lecture.mp4", "size": 12417467 }]
}'
# Send the file to its part link: files[0].parts[0].url in the answer.
curl -X PUT --upload-file lecture.mp4 "$PART_URL"
# Complete the upload, which checks the file.
curl -X POST https://api.filesokay.com/v1/uploads/file_3cf0737aefa34b89b7b4443c9467d60c/complete \
-H "Authorization: Bearer $FILESOKAY_KEY"const name = "lecture.mp4";
const { size } = fs.statSync(name);
// Start the upload with the file's name and size in bytes.
const { files: [upload] } = await api("POST", "/uploads", {
operation: "video.compress",
files: [{ name, size }],
});
// Send the file to its link, straight from disk. The link carries its own permission: no key.
await new Promise((resolve, reject) => {
const req = https.request(upload.parts[0].url, {
method: "PUT",
headers: { "Content-Length": size },
});
req.on("response", (res) => {
res.resume();
if (res.statusCode === 200) resolve();
else reject(new Error(`Upload failed: ${res.statusCode}`));
});
req.on("error", reject);
fs.createReadStream(name).on("error", reject).pipe(req);
});
// Complete the upload, which checks the file.
const uploaded = await api("POST", `/uploads/${upload.id}/complete`);
console.log(uploaded.check.state);name = "lecture.mp4"
# Start the upload with the file's name and size in bytes.
upload = api("POST", "/uploads", {
"operation": "video.compress",
"files": [{"name": name, "size": os.path.getsize(name)}],
})["files"][0]
# Send the file to its link, straight from disk. The link carries its own permission: no key.
with open(name, "rb") as f:
requests.put(upload["parts"][0]["url"], data=f).raise_for_status()
# Complete the upload, which checks the file.
uploaded = api("POST", f"/uploads/{upload['id']}/complete")
print(uploaded["check"]["state"]){
"id": "file_3cf0737aefa34b89b7b4443c9467d60c",
"name": "lecture.mp4",
"operation": "video.compress",
"state": "uploaded",
"size": 12417467,
"created_at": "2026-12-03T08:59:54Z",
"uploaded_at": "2026-12-03T09:00:00Z",
"delete_at": "2026-12-04T09:00:00Z",
"check": {
"state": "proceed",
"kind": "video",
"type": "mp4",
"facts": {
"container": "mp4",
"protection": "none",
"attachments": [],
"duration_ms": 20023,
"frame_count": 600,
"audio_tracks": [
{
"codec": "aac",
"channels": 1,
"sample_rate": 44100
}
],
"video_tracks": [
{
"hdr": "none",
"codec": "h264",
"width": 1280,
"chroma": "420",
"height": 720,
"profile": "High",
"rotation": 0,
"bit_depth": 8,
"frame_rate": 30,
"interlaced": false,
"variable_frame_rate": false
}
],
"data_end_bytes": 12417467,
"subtitle_tracks": []
},
"facts_complete": true
}
}proceed means a job can use the file. A file up to 5 GB goes in one request. Uploading files shows how to send larger ones.
Name the operation and the file. Settings you leave out take their defaults, which for video.compress is a balanced quality level. The Idempotency-Key header makes a retry safe: see safe retries.
curl 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" }]
}'const job = await api(
"POST",
"/jobs",
{ operation: "video.compress", inputs: [{ file_id: upload.id }] },
{ "Idempotency-Key": crypto.randomUUID() },
);
console.log(job.id, job.status);job = api(
"POST",
"/jobs",
{"operation": "video.compress", "inputs": [{"file_id": upload["id"]}]},
{"Idempotency-Key": str(uuid.uuid4())},
)
print(job["id"], job["status"]){
"id": "job_a1c9531eeb00434aba0058796f1ca517",
"operation": "video.compress",
"status": "waiting",
"client_reference": null,
"settings": {
"audio": "keep",
"codec": "same",
"level": "balanced",
"method": "quality",
"frame_rate": "original",
"resolution": "original",
"output_format": "same"
},
"created_at": "2026-12-03T09:00:12Z",
"reserved_credits": 2,
"charged_credits": 0,
"tasks": [
{
"id": "task_4256d03a73a741afa1821546a2bcba98",
"status": "waiting",
"progress": 0,
"reserved_credits": 2,
"inputs": [
{
"file_id": "file_3cf0737aefa34b89b7b4443c9467d60c",
"name": "lecture.mp4"
}
],
"outputs": []
}
]
}The job starts at once and runs in the background. Its credits are reserved now, and it’s charged only what it uses.
Ask for the job every 5 seconds until its status is no longer waiting or processing. In your own app, a webhook can tell you when the job ends, so you don’t have to keep asking.
# Ask again every few seconds until the status is no longer waiting or processing.
curl https://api.filesokay.com/v1/jobs/job_a1c9531eeb00434aba0058796f1ca517 \
-H "Authorization: Bearer $FILESOKAY_KEY"let current = job;
while (current.status === "waiting" || current.status === "processing") {
await new Promise((resolve) => setTimeout(resolve, 5000));
current = await api("GET", `/jobs/${job.id}`);
}
console.log(current.status);current = job
while current["status"] in ("waiting", "processing"):
time.sleep(5)
current = api("GET", f"/jobs/{job['id']}")
print(current["status"]){
"id": "job_a1c9531eeb00434aba0058796f1ca517",
"operation": "video.compress",
"status": "completed",
"client_reference": null,
"settings": {
"audio": "keep",
"codec": "same",
"level": "balanced",
"method": "quality",
"frame_rate": "original",
"resolution": "original",
"output_format": "same"
},
"created_at": "2026-12-03T09:00:12Z",
"started_at": "2026-12-03T09:00:30Z",
"finished_at": "2026-12-03T09:00:51Z",
"reserved_credits": 2,
"charged_credits": 1,
"tasks": [
{
"id": "task_4256d03a73a741afa1821546a2bcba98",
"status": "completed",
"progress": 100,
"reserved_credits": 2,
"charged_credits": 1,
"inputs": [
{
"file_id": "file_3cf0737aefa34b89b7b4443c9467d60c",
"name": "lecture.mp4"
}
],
"outputs": [
{
"file_id": "file_8dd09e1ec2fb42c1940e4ef92a153a4e",
"name": "lecture-compressed.mp4",
"size": 7268734,
"download_url": "https://…",
"download_expires_at": "2026-12-06T09:00:51Z"
}
]
}
]
}Each completed task lists its results, each with a link that downloads the file under its own name. The link works for up to 7 days and needs no key.
# The link is tasks[0].outputs[0].download_url in the job. It needs no key.
curl -o lecture-compressed.mp4 "$DOWNLOAD_URL"for (const task of current.tasks) {
for (const output of task.outputs) {
const res = await fetch(output.download_url);
if (!res.ok) throw new Error(`${output.name}: ${res.status}`);
await pipeline(Readable.fromWeb(res.body), fs.createWriteStream(output.name));
console.log(`Saved ${output.name}: ${output.size} bytes`);
}
}for task in current["tasks"]:
for output in task["outputs"]:
with requests.get(output["download_url"], stream=True) as res:
res.raise_for_status()
with open(output["name"], "wb") as f:
for chunk in res.iter_content(chunk_size=1 << 20):
f.write(chunk)
print(f"Saved {output['name']}: {output['size']} bytes")In this example, lecture.mp4 went from 12.4 MB to 7.3 MB, for 1 credit.
- Running jobs
Settings, estimates, batches and statuses.
- Webhooks
Stop asking: get a signed message when a job ends.
- Error codes
Handle every error by its code.