MATLAB webwrite and weboptions: generate an AI video and save the MP4
A MATLAB script posts a Wan 3.0 job to Sume with webwrite, polls the job status with webread and saves the finished clip with websave.

In MATLAB, three built-ins cover the whole flow: webwrite to submit a job, webread to poll it, and websave to download the result, each with a weboptions object that carries the Authorization header. Sume answers POST /v1/videos with a job id; you read GET /v1/jobs/{id}/status until terminal is true and then fetch /v1/videos/{id}/content?index=0 (Sume jobs guide, read 2026-10-06).
Researchers use this to make a short illustrative clip from a script without leaving the Live Editor. The example is wan-3.0, 5 seconds, 720p: $0.625 at $0.125 per second.
What is the script?
Set the SUME_API_KEY environment variable before starting MATLAB. With MediaType set to application/json, webwrite encodes the struct as a JSON body.
key = getenv('SUME_API_KEY');
assert(~isempty(key), 'SUME_API_KEY is empty');
base = 'https://api.sume.com';
auth = {'Authorization', ['Bearer ' key]};
postOpts = weboptions('MediaType', 'application/json', 'Timeout', 30, ...
'HeaderFields', [auth; {'Idempotency-Key', 'matlab-fog-001'}]);
job = webwrite([base '/v1/videos'], struct( ...
'model', 'wan-3.0', 'prompt', 'Fog drifting over a lab bench', ...
'duration', 5, 'resolution', '720p'), postOpts);
getOpts = weboptions('HeaderFields', auth, 'Timeout', 30);
for k = 1:120
pause(15);
s = webread([base '/v1/jobs/' job.id '/status'], getOpts);
if s.terminal, break; end
end
assert(strcmp(s.sume_status, 'completed'), 'job ended as %s', s.sume_status);
websave('clip.mp4', [base '/v1/videos/' job.id '/content?index=0'], getOpts);What does each resolution cost?
| Resolution | Per second | 5-second clip |
|---|---|---|
| 480p | $0.0625 | $0.3125 |
| 720p | $0.125 | $0.625 |
| 1080p | $0.25 | $1.25 |
Does re-running the script bill a second clip?
It can if you re-run the submit step. Send a stable Idempotency-Key on POST /v1/videos (here a fixed string; in practice a row id) so a repeat returns the original job. A give-up on the client never cancels the render, so keep the job id and read it again (Sume jobs guide, read 2026-10-06).
Sources
Related posts
More in Developers
- Music-only Short: Timeline silence mode with a soundtrack bed
Build a Short with no voice: audio mode silence plus a soundtrack. The bed plays alone at the default -16 dB with no amix loss. Fields, limits, tail rule.
- Nearest supported aspect ratio per Sume image model, in Python
A model rejects an aspect ratio it does not list. Read the catalog, pick the closest ratio it accepts, generate, then crop to the exact shape you need.
- NestJS raw body controller to verify an AI video webhook signature
Enable rawBody in NestFactory, read req.rawBody in a controller and check Sume's sume-v1 HMAC before you act on a job.completed video event.
- Never set toleranceSeconds to 0 on a Sume webhook verifier
toleranceSeconds 0 skips the timestamp check, so a captured delivery verifies forever. See the replay and a WebCrypto verifier that rejects stale ones.
Written by Sume