curl -w http_code: branch a Sume video submit in bash on 202, 402, 429

A bash submit that saves the body, reads the HTTP code with curl -w and branches on 202, 402, 429 and 5xx. Three Wan 3.0 payloads cost $1.875, $3.75 and $7.50.

4 min readSume
All posts

curl exits 0 on a 402 or a 429 unless you pass --fail, so a bash submit has to read the HTTP code itself with -w '%{http_code}' and branch on it. One case statement can handle 202 (store the id), 402 (stop, top up), 429 (wait, same key) and 5xx (retry, same key).

What each payload is worth

The three payloads below are 30 s Wan 3.0 clips. A 402 insufficient_credits on any of them means no job was started, and the reserve is not taken.

Branching on the code keeps a script from treating an error body as a job id.

Payloads for the script, 30 s Wan 3.0 (read 2026-10-09)
ResolutionRate per second30 s totalExpected on success
480p$0.0625$1.875202 with id and polling_url
720p$0.125$3.75202 with id and polling_url
1080p$0.25$7.50202 with id and polling_url

The submit

The key is generated once, so a rerun of the same script run with the same KEY adopts the first job.

KEY=${KEY:-$(uuidgen)}
CODE=$(curl -sS -o body.json -w '%{http_code}' -m 30 \
  -X POST https://api.sume.com/v1/videos \
  -H "Authorization: Bearer $SUME_API_KEY" \
  -H "Idempotency-Key: $KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"wan-3.0","prompt":"Rain on a tin roof","duration":30,"resolution":"720p"}')
case "$CODE" in
  202) jq -r '.id' body.json ;;
  402) echo "top up first" >&2; exit 3 ;;
  429|500|502|503) echo "retry with KEY=$KEY" >&2; exit 4 ;;
  *) jq -r '.error.code + ": " + .error.message' body.json >&2; exit 1 ;;
esac

Gotchas

If curl times out (exit 28), you do not know what happened; rerun with the same KEY exported instead of generating a new one. The error envelope is {error:{code,message,request_id,details}}, so the jq in the last branch works for every 4xx.

Send only one credential: Authorization and x-api-key together returns 401.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume