A "use step" function that submits a Sume job once

Put the Sume submit call inside one "use step" function and derive the Idempotency-Key from a stable run key, so a retried step returns the original job.

4 min readSume
All posts

Workflow Development Kit v4.8.11, released Oct 1, 2026, fixed directive discovery for the "use step" and "use workflow" statements, per the Vercel release notes. For Sume, wrap the paid submit in one "use step" function and pass an Idempotency-Key built from a stable run key, so a retry returns the original job instead of billing a second one.

Why the key matters

Sume's docs say to send Idempotency-Key on submit requests when retrying after a client-side timeout or network failure, and that a replay returns the original job. Reuse the same key only for the same operation and payload. A durable step that can be retried is exactly the case that rule exists for.

The step

The key must be the same on every attempt of the step, so it cannot come from Date.now() or a random value created inside the step. Pass it in as an argument that comes from the workflow's own input or run id:

async function submitSumeJob(runKey: string, prompt: string) {
  "use step";
  const apiKey = process.env.SUME_API_KEY;
  if (!apiKey) throw new Error("SUME_API_KEY is not set");
  const res = await fetch("https://api.sume.com/v1/video-router/generate", {
    method: "POST",
    headers: {
      "x-api-key": apiKey,
      "Content-Type": "application/json",
      "Idempotency-Key": runKey,
    },
    body: JSON.stringify({
      model: "seedance-2.5",
      prompt,
      duration: 8,
      resolution: "720p",
      aspect_ratio: "9:16",
      mode: "async",
    }),
  });
  if (!res.ok) throw new Error(`Sume submit failed: ${res.status}`);
  return res.json();
}

Separate submit from wait

Keep the submit in its own step and the waiting in another. A step that both submits and polls can be retried after the paid job is already running. With the key fixed, even that retry is safe, but a separate step is easier to reason about.

  • Step 1: submit with a stable Idempotency-Key, return the job id
  • Step 2: poll GET /v1/jobs/{id}/status with backoff until terminal
  • Step 3: read GET /v1/jobs/{id}/result and pass the artifact URL on
  • Never resubmit a paid request because a poll timed out

Sources

Related posts

More in Developers

All Developers posts

Written by Sume