Generate an AI video with curl and jq in one Bash script

One Bash script that submits a Sume video job with curl, polls until it finishes, and prints the file URL and the cost. A 6-second clip is 75 cents.

5 min readSume
All posts

For a cron job or a CI step, curl and jq are enough. Sume's /v1/videos is asynchronous, so the script submits once and then polls the URL the first response gives back.

The code

Set SUME_API_KEY. The program submits one job, polls polling_url every 20 seconds until completed, and prints the first download URL.

#!/usr/bin/env bash
set -euo pipefail
AUTH="Authorization: Bearer ${SUME_API_KEY:?set SUME_API_KEY}"
POLL=$(curl -sf https://api.sume.com/v1/videos \
  -H "$AUTH" -H 'Content-Type: application/json' \
  -d '{"model":"sume/auto","prompt":"Steam over a night market","aspect_ratio":"9:16","duration":6}' \
  | jq -r .polling_url)
while true; do
  JOB=$(curl -sf "$POLL" -H "$AUTH")
  STATUS=$(jq -r .status <<<"$JOB")
  echo "status: $STATUS" >&2
  case "$STATUS" in
    completed) jq -r '.unsigned_urls[0], .usage.cost' <<<"$JOB"; break ;;
    failed|cancelled) echo "$JOB" >&2; exit 1 ;;
  esac
  sleep 20
done

What to know

A 6-second sume/auto clip at the default 720p costs 75 cents (list $0.10 per second x 1.25 x 6 s = $0.75). The script prints the download URL and then usage.cost, the billable amount, so a pipeline can append it to a ledger.

Download the file with curl -o clip.mp4 and the first printed URL. Add an Idempotency-Key header to the POST when your scheduler may retry the script, so a retry does not create a second job.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume