Check Sume artifact size, width and duration before you download

Read size_bytes, width, height and duration_ms from the job result and reject an unexpected artifact before spending bandwidth. Node 18 TypeScript sample.

5 min readSume
All posts

Each artifact in data.result.artifacts can carry size_bytes, width, height and duration_ms, so you can validate a render before you download it. All four are nullable integers, so treat null as unknown rather than as zero.

Fields and sensible checks

The checks are plain comparisons against limits you choose. Sume does not enforce them for you.

Artifact metadata fields (read 2026-10-04)
FieldNullableExample check
size_bytesyesReject above the upload cap of your next system.
width / heightyesMatch the aspect ratio you asked for.
duration_msyesCompare with the duration in the request.
content_typeyesExpect video/mp4 for a video job.

TypeScript

This runs on Node 18 or later with the built-in fetch. Compile with any TypeScript setup or strip the types.

const base = "https://api.sume.com/v1";
const key = process.env.SUME_API_KEY;
if (!key) throw new Error("SUME_API_KEY is not set");
const headers = { "x-api-key": key };

type Artifact = {
  id: string; url: string; content_type: string | null;
  size_bytes: number | null; width: number | null; height: number | null; duration_ms: number | null;
};

async function main(jobId: string, maxBytes: number, expectedSeconds: number) {
  const res = await fetch(`${base}/jobs/${jobId}/result`, { headers });
  if (!res.ok) throw new Error(`result ${res.status}: ${await res.text()}`);
  const { data } = await res.json();
  for (const a of data.result.artifacts as Artifact[]) {
    const problems: string[] = [];
    if (a.size_bytes != null && a.size_bytes > maxBytes) problems.push(`size ${a.size_bytes}`);
    if (a.duration_ms != null && Math.abs(a.duration_ms / 1000 - expectedSeconds) > 1) problems.push(`duration ${a.duration_ms}ms`);
    console.log(a.id, problems.length ? `REJECT ${problems.join(", ")}` : "ok", a.width, a.height);
  }
}

main(process.argv[2], 50_000_000, Number(process.argv[3])).catch((e) => { console.error(e); process.exit(1); });

What not to infer

Artifact URLs sit on the Sume media CDN and are opaque. The schema says clients must not parse them, so do not read the file size or the job from the path. Use the fields above, and use the checksum after the download.

Timing

GET /v1/jobs/{id}/result returns 409 job_not_completed until the job is completed. Gate the call on the status route's terminal and result_ready flags rather than catching the 409 in a loop.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume