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.

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.
| Field | Meaning | Used for |
|---|---|---|
| id | Job id | Printed beside the cost |
| status | pending, in_progress, completed, failed, cancelled | Filter: completed only |
| usage.cost | Sume billable USD amount | Summed by awk |
| unsigned_urls | Content routes of the finished video | Not 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
- Transcribe a 15-second voice note in one request: STT sync mode
Sume STT can answer in the same HTTP call: mode sync with wait_timeout_seconds up to 30 returns 200, otherwise 202 and a poll. A $0.01 minimum, with curl.
- Transcribe the first 60 seconds of 500 support recordings
500 screen-recorded support sessions: detach seconds 0 to 60 ($5.00), then STT 60 s each ($5.00). Total $10.00 at $0.01 per job and per minute.
- Trim 12 Shorts from one recording with asyncio and a semaphore
Cut 12 Shorts from one recording with asyncio and httpx: 12 trims at $0.02 is $0.24. A semaphore of 4 caps in-flight requests; the limit is your choice.
- TTS 1.0 rejects a model field: use the TTS router to pick sonic-3.6
Sume TTS 1.0 does not accept model. To choose an engine such as sonic-3.6 use /v1/tts-router/generate. Price is the same $0.0475 per 1,000 characters.
Written by Sume