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.

4 min readSume
All posts

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?

Sume Wan 3.0 per-second rates (list x 1.25) and 5-second totals, from the Sume catalog, read 2026-10-06
ResolutionPer second5-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

All Developers posts

Written by Sume