Total usage.cost for Sume video job ids with curl, jq and awk

One shell pipeline: read job ids from a file, GET /v1/videos/{id} for each, keep completed jobs, and sum usage.cost with awk. No Python or Node needed.

5 min readSume
All posts

To total what a batch of Sume video jobs cost, loop over the job ids, call GET /v1/videos/{id} for each, keep the ones with status completed, print usage.cost, and let awk add the numbers. The script is eight lines of bash with curl, jq and awk, and it prints one line per clip and a total at the end, for example total 3.1250 over 1 completed clips.

What usage.cost is

On a completed /v1/videos job, usage.cost is the Sume billable amount in USD. Sume bills the provider list price times 1.25, and the per-second prices in its list include that, so for a 25-second wan-3.0 clip at 720p the figure is 25 x 0.125 = $3.125. The cost field is the right source for your books because it comes from the job, not from your own price table.

Fields the script reads (Sume docs, read 2026-10-09)
FieldMeaningUsed for
idJob idPrinted beside the cost
statuspending, in_progress, completed, failed, cancelledFilter: completed only
usage.costSume billable USD amountSummed by awk
unsigned_urlsContent routes of the finished videoNot used here

How the pipeline works

job-ids.txt has one id per line. For each one, curl -fsS fails on HTTP errors and stays quiet otherwise, and jq selects completed jobs and prints the id and cost. The loop output feeds awk, which adds field 2 into s, counts lines in n and prints each row at four decimals. The END block prints the total.

set -euo pipefail makes a failed request stop the script instead of silently producing a short total. A 404 for an id that belongs to another workspace is a real error: Sume answers not_found for resources outside the current workspace.

#!/usr/bin/env bash
set -euo pipefail
# job-ids.txt: one /v1/videos job id per line
while read -r id; do
  curl -fsS "https://api.sume.com/v1/videos/$id" -H "Authorization: Bearer $SUME_API_KEY" |
    jq -r --arg id "$id" 'select(.status == "completed") | "\($id) \(.usage.cost)"'
done < job-ids.txt |
  awk '{ s += $2; n++; printf "%s %.4f\n", $1, $2 }
       END { printf "total %.4f over %d completed clips\n", s, n }'

What it leaves out on purpose

The script counts completed jobs only. Whether a failed or cancelled job was charged is a question for the job's own record, not for this tally, so it is not folded in. If the numbers will go into an invoice, replace awk with a decimal tool: awk sums floating-point values, which is fine for 4 decimals and a handful of jobs and not fine for a ledger. A Python Decimal ledger does the same sum exactly.

A hundred ids means a hundred sequential reads. That is far below the per-minute read budget on every plan (4,800 on Free), but run it with a short sleep if you wrap it in a loop.

To get ids into the file, log them at submit time, one per line, together with the date. A month later the pipeline turns that file into a total you can match with the balance history. If you need a per-model breakdown, add .model to the jq output and group in awk with an associative array keyed on field 3.

  • Keep the id file with the date of the run.
  • Re-run is safe; reads change nothing.
  • Compare the total with your balance change for the same period.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume