createSumeClient custom fetch: log ratelimit-remaining as you go
Pass your own fetch to createSumeClient to warn when ratelimit-remaining runs low, without wrapping every SDK call. Works on Node 18+, Bun, Deno, Workers.

The seam
createSumeClient takes three options: apiKey (required), baseUrl, and fetch. The docs describe fetch as the place to supply your own function for instrumentation, retries or tests. The default is the runtime's globalThis.fetch, and the package has no runtime dependencies, so a wrapper is all you need.
Every generated operation and every helper such as waitForJob goes through that one function, which makes it the right place to watch the rate-limit headers instead of sprinkling logging at call sites.
Headers worth logging (read 2026-10-05)
| Header | Meaning |
|---|---|
| ratelimit-limit | Requests permitted in the current window |
| ratelimit-remaining | Requests left in the current window |
| ratelimit-reset | Seconds until the window resets |
| retry-after | Seconds to wait, sent on 429 |
A logging fetch
The headers describe the budget the current request spent from, read or write, so log the method with the number. This wrapper warns under 50 remaining and passes the response through untouched, so the SDK's own retry logic still sees it.
import { createSumeClient } from "@sume-com/sdk";
const loggingFetch: typeof fetch = async (input, init) => {
const res = await fetch(input, init);
const left = res.headers.get("ratelimit-remaining");
if (left !== null && Number(left) < 50) {
console.warn(
"sume budget low:", (init?.method ?? "GET"), left,
"reset in", res.headers.get("ratelimit-reset"), "s",
);
}
return res;
};
export const client = createSumeClient({
apiKey: process.env.SUME_API_KEY!,
fetch: loggingFetch,
});Keep it a pure observer
Do not add your own retries inside this wrapper. The client already retries 408, 429 and 5xx twice with backoff and jitter, and it retries a POST only when the request carries an Idempotency-Key. Retrying a keyless POST here would start and bill a second job. Log, count, and return the response.
Sources
Related posts
More in Developers
- C# HttpClient and Sume images: keep the key off the download call
Reuse one HttpClient, but set the bearer header per request, not as a default header, or it also rides along when you download the Sume image URL.
- C# HttpClient for Sume video jobs: a Sora port in 30 lines
A .NET top-level program that posts to Sume /v1/videos with an Idempotency-Key, polls to a terminal status, and saves the mp4. For C# teams that wrapped Sora.
- curl and jq: poll a Seedance 2.5 clip from a bash script
A bash script with curl and jq that submits a 30-second Seedance 2.5 job to Sume, polls every 30 seconds and saves the MP4, with costs at three resolutions.
- Smoke-test a video API key with curl: a $0.11 Omni clip
A 19-line curl and jq script: submit a 3-second 360p Gemini Omni Flash 1.1 job, poll it, save the MP4. At $0.0375 a second the test costs $0.1125.
Written by Sume