Sume SDK returns {data, error}, not exceptions: an unwrap helper
Generated @sume-com/sdk operations resolve with data, error and response instead of throwing. Wrap them in an unwrap helper that throws a typed error.

Generated operations in @sume-com/sdk do not throw on an API error; they resolve with { data, error, response }. That is easy to miss inside a retrying task runner, where a swallowed error looks like success. One unwrap function that throws a typed error fixes it.
Which helpers do throw
The docs split the behavior: generated operations resolve with the triple, while subscribeFormatRun and waitForRun throw, because a poll loop has nowhere to put a non-result. So your code needs both a try/catch for the helpers and the unwrap for the generated calls.
The helper
The error body is the Sume envelope, with error.code and error.request_id, so the thrown error can carry both.
export class SumeError extends Error {
constructor(
public status: number,
public code: string,
message: string,
public requestId?: string,
) {
super(message);
}
}
export function unwrap<T>(r: { data?: T; error?: any; response: Response }): T {
if (r.error || r.data === undefined) {
const e = r.error?.error ?? {};
throw new SumeError(
r.response.status,
e.code ?? "unknown",
e.message ?? "request failed",
e.request_id,
);
}
return r.data;
}Then branch on the code
With a thrown SumeError, your retry layer can switch on code: retry rate_limited and provider_capacity_exceeded with the same idempotency key, stop on insufficient_credits, and fix the input on invalid_request.
| Call | On API error |
|---|---|
| Generated operations | Resolve with data, error, response |
| subscribeFormatRun, waitForRun | Throw |
| waitForJob | Throws SumeJobRequestError or SumeJobTimeoutError |
Sources
Related posts
More in Developers
- Where the Sume TypeScript SDK runs: Node 18+, Bun, Deno and Workers
@sume-com/sdk has no runtime dependencies and needs only fetch and WebCrypto. Install it, create a client, and know which options and helpers it adds.
- Sume video callback_url must be HTTPS: a webhook instead of polling
POST /v1/videos accepts callback_url, which must be HTTPS. Event names, the signature header, retries, and when a poll loop is still the safer choice.
- Sume video job failed: retry, new key, or switch the model?
A failed video job is final, and an Idempotency-Key replay returns the same failed job. Read the error, then retry with a new key or change models.
- Sume webhooks plus a sweeper: recover jobs whose callback never came
Webhook delivery can fail after 10 attempts while the Sume job still finishes. Run a sweeper that polls jobs stuck non-terminal in your own table.
Written by Sume