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.

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.
| Resolution | Rate per second | 30 s total | Expected on success |
|---|---|---|---|
| 480p | $0.0625 | $1.875 | 202 with id and polling_url |
| 720p | $0.125 | $3.75 | 202 with id and polling_url |
| 1080p | $0.25 | $7.50 | 202 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 ;;
esacGotchas
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
- Cut dead air before the first word: STT start time, $0.01 split
Read words[0].start from a Sume STT job, then split the recording from that second for $0.01. For a 3-minute take the whole fix is $0.04. A copyable request.
- Deno fetch: 25 s Wan 3.0 clip costs $3.125, 20-minute deadline
Deno script: submit a 25-second Wan 3.0 clip to Sume at 720p ($3.125), poll with backoff, stop at a 20-minute deadline. Run with deno run -A.
- Deno.serve webhook receiver for Sume jobs: Web Crypto HMAC, rotation
Verify Sume job webhooks in Deno with Web Crypto: refuse an empty secret, accept any rotation entry, 300 s tolerance, return 204. Retry window is 370 s.
- Idempotency-Key from a body hash plus a take number (Node, Sume)
Build an Idempotency-Key for Sume /v1/videos from a SHA-256 of the body plus a take counter, so a retry replays and a re-roll pays. Node code.
Written by Sume