Submit and poll a Sume video job from Rust with reqwest

Rust reqwest blocking client for Sume /v1/videos: submit a sume/auto job, poll until completed, print the download URL and usage.cost. Cargo features listed.

5 min readSume
All posts

Rust teams can call Sume's /v1/videos with reqwest in blocking mode and read the job as serde_json::Value, which avoids writing structs for a response with only four fields you care about.

The code

Set SUME_API_KEY. The program submits one job, polls polling_url every 20 seconds until completed, and prints the first download URL.

use serde_json::{json, Value};
use std::{env, thread, time::Duration};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let key = env::var("SUME_API_KEY")?;
    let c = reqwest::blocking::Client::new();
    let body = json!({"model": "sume/auto", "prompt": "Fog rolling over a ridge", "aspect_ratio": "9:16"});
    let job: Value = c.post("https://api.sume.com/v1/videos").bearer_auth(&key).json(&body).send()?.json()?;
    let poll = job["polling_url"].as_str().ok_or("no polling_url")?.to_string();
    loop {
        thread::sleep(Duration::from_secs(20));
        let s: Value = c.get(&poll).bearer_auth(&key).send()?.json()?;
        match s["status"].as_str() {
            Some("completed") => {
                println!("{} {}", s["unsigned_urls"][0], s["usage"]["cost"]);
                return Ok(());
            }
            Some("failed") | Some("cancelled") => return Err(s.to_string().into()),
            _ => {}
        }
    }
}

What to know

Cargo.toml needs reqwest = { version = "0.12", features = ["blocking", "json"] } and serde_json = "1". This sample was written against the documented response shape and was not compiled in this session, so run cargo check first.

sume/auto currently resolves to Gemini Omni Flash 1.1 and takes 3 to 10 seconds in 16:9 or 9:16. The defaults are 720p and 8 seconds, so this call bills $1.00 (list $0.10 per second x 1.25 x 8 s). A failed or cancelled job ends the loop with a non-success status; check error in the poll body.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume