PowerShell 7: submit, poll and save a Sume video, no SDK

A Windows-friendly script for POST /v1/videos: Idempotency-Key, a 30-second poll on polling_url, and a download from unsigned_urls[0]. Fits in 14 lines.

5 min readSume
All posts

Use Invoke-RestMethod to POST the job to https://api.sume.com/v1/videos, read polling_url from the 202 response, poll it until status leaves pending and in_progress, and download unsigned_urls[0] with the same Authorization header. The response is a bare object, so $job.polling_url works without any .data step.

The script

The script below uses wan-3.0 at 720p, 9:16, five seconds. Set $env:SUME_API_KEY first. One Idempotency-Key is created once per script run, so a re-run of the submit line (for example after a network error) returns the original job instead of a second paid one. A new run of the script gets a new key and a new job.

$h = @{ Authorization = "Bearer $env:SUME_API_KEY" }
$key = [guid]::NewGuid().ToString()
$body = @{
  model = "wan-3.0"; prompt = "A paper boat on a rainy street, slow dolly in"
  duration = 5; resolution = "720p"; aspect_ratio = "9:16"
} | ConvertTo-Json
$job = Invoke-RestMethod -Method Post -Uri "https://api.sume.com/v1/videos" `
  -Headers ($h + @{ "Idempotency-Key" = $key }) `
  -ContentType "application/json" -Body $body
Write-Host "job $($job.id) $($job.status)"
do {
  Start-Sleep -Seconds 30
  $s = Invoke-RestMethod -Uri $job.polling_url -Headers $h
  Write-Host $s.status
} while ($s.status -in "pending", "in_progress")
if ($s.status -ne "completed") { throw "ended as $($s.status): $($s.error)" }
Invoke-WebRequest -Uri $s.unsigned_urls[0] -Headers $h -OutFile clip.mp4

What the fields mean

Statuses on this surface are pending, in_progress, completed, failed and cancelled. The loop above exits on any of the last three. A failed job puts one string in error, and cancelled has none, so the throw prints whatever is there.

Poll fields used by the script, per the Sume video docs (read 2026-10-08)
FieldUsed for
idthe job id; also readable at GET /v1/jobs/{id}/status
polling_urlthe URL to GET in the loop
statusloop exit condition
unsigned_urlsdownload links, one per output, on completed jobs
errora single string on failed jobs

Cost and polling

The docs suggest a moderate polling interval such as 30 seconds, and say video generation usually takes from 30 seconds to several minutes. At that interval a five-minute job costs about ten GET requests.

For this request the price is worked out from the Sume catalog: wan-3.0 at 720p lists at $0.10 per second, Sume bills list x 1.25, so 5 s x $0.10 x 1.25 = $0.625, rounded up to $0.63. The poll shows that amount in usage.cost (see the grid in the Sume video docs).

  • -ContentType is required on the POST: a body that is not application/json is answered with 415.
  • Never write the key into the script; read it from the environment as shown.

If it stalls

A job that stays pending for a long time is normally just queued. Keep polling at the same interval. If you would rather not poll, add callback_url (HTTPS) to the body and verify the signed delivery instead; see the reconcile sweeper for keeping a poll as the backup.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume