PowerShell: Invoke-RestMethod for a 30-second Wan 3.0 clip

Windows PowerShell script that posts a 30-second wan-3.0 job, loops until it completes and saves the MP4 with Invoke-WebRequest. $3.75 at 720p.

3 min readSume
All posts

On Windows you do not need curl or an SDK to make a 30-second Wan 3.0 clip: Invoke-RestMethod posts the job and parses the JSON, a do ... while loop waits, and Invoke-WebRequest -OutFile saves the MP4. The 720p, 9:16 request below is reserved at $3.75.

The script

Set SUME_API_KEY in the environment first ($env:SUME_API_KEY = ... for the session). The script stops if it is empty.

if (-not $env:SUME_API_KEY) { throw "SUME_API_KEY is empty" }
$auth = @{ Authorization = "Bearer $env:SUME_API_KEY" }
$base = "https://api.sume.com/v1/videos"
$body = @{
  model = "wan-3.0"; prompt = "A barista pouring latte art, overhead shot"
  duration = 30; resolution = "720p"; aspect_ratio = "9:16"
} | ConvertTo-Json
$job = Invoke-RestMethod -Method Post -Uri $base -Headers ($auth + @{ "Idempotency-Key" = "wan-ps-001" }) `
  -ContentType "application/json" -Body $body
do {
  Start-Sleep -Seconds 5
  $s = Invoke-RestMethod -Uri "$base/$($job.id)" -Headers $auth
} while ($s.status -in "pending", "in_progress")
if ($s.status -ne "completed") { throw "Job ended as $($s.status)" }
Invoke-WebRequest -Uri "$base/$($job.id)/content?index=0" -Headers $auth -OutFile clip.mp4

Notes for Windows scripts

  • duration stays an integer in ConvertTo-Json; PowerShell numbers serialise as numbers, so 30 is sent as 30.
  • On a failed submit, Invoke-RestMethod throws. In PowerShell 7 the response body is in $_.ErrorDetails.Message, which is where a 402 insufficient_credits explanation appears.
  • The idempotency key belongs on the POST only. Use a new key when the prompt or resolution changes.

Reserve per resolution

Sume list price for wan-3.0, read 2026-10-08
resolutionReserve for 30 sPer second
480p$1.875$0.0625
720p$3.75$0.125
1080p$7.50$0.25

Failure cases to handle

Three responses matter for a paid submit.

  • 402 insufficient_credits: Sume cannot reserve the estimated cost from the workspace balance. Submit a less expensive request or wait for included Gen$ or a plan upgrade, then submit again.
  • 409 idempotency_conflict: the key was used for a different payload. Mint a new key for a genuinely new request.
  • 429: the workspace has no accepted-job capacity right now. Wait, then retry with the same key; the Generation admission page lists the codes.

Task Scheduler

To run it nightly, save the script and register it with Task Scheduler, passing the key through a machine or user environment variable rather than writing it into the script. If the machine may sleep mid-job, store $job.id in a file; the job keeps running on Sume's side and you can poll the same id later.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume