Node 26.11 isValidHeaderValue: check a Sume Idempotency-Key first
Node 26.11 adds http.isValidHeaderValue. Use it to reject a bad Idempotency-Key before POST /v1/images, with a fallback for older Node, and see its limits.

Yes: since Node.js 26.11.0 you can call http.isValidHeaderValue(value) on the string you plan to send as Idempotency-Key and refuse to submit when it returns false. The 26.11.0 release notes list http.isValidHeaderName() and http.isValidHeaderValue() as new, and the http reference gives the signature as isValidHeaderValue(value[, options]) returning a boolean. It is a syntax check on one header value. It does not know anything about Sume.
Why bother? A key built from an order id, a customer note or a pasted string can contain a newline or a control character. A request with such a header fails inside your HTTP client before the server sees it, and if your retry wrapper treats every thrown error as transient, you can loop on a request that can never be sent. Checking the key once, up front, turns that into one clear error at the call site.
What the check covers and what it does not
The table lists the facts this post relies on. Sume accepts an Idempotency-Key header on submit routes: the same key with the same payload returns the original job, and a different payload under the same key returns a 409, as described in the jobs and results docs.
Node's helper answers only whether the string is a legal HTTP header value. It cannot tell you whether the key is a good key. Choosing a stable key per logical order, and keeping it across retries, is still your job.
| Question | Answer | Source |
|---|---|---|
| Which Node release adds isValidHeaderValue? | 26.11.0, published Oct 7, 2026 | Node release notes |
| Signature | isValidHeaderValue(value[, options]) returns boolean | Node http reference |
| Does it check Sume key policy? | No, header syntax only | Node http reference |
| Same key, same payload to Sume | Returns the original job, idempotency_hit is true | Sume jobs docs |
| Same key, different payload to Sume | 409 idempotency_conflict | Sume jobs docs |
Steps
- Build the key from stable business data, for example an order id plus a version, or a UUID you store with the order.
- Call the helper before the first request. If it is missing (Node 22, 24), fall back to
http.validateHeaderValue(name, value), which throws on an illegal value. - Send the same key on every retry of that submit. Never generate a new key inside a retry loop.
- On a 202 or 200, store the returned job id next to the key so a restarted process can poll instead of resubmitting.
Runnable sample
This script submits an async image job. It feature-detects the new helper and works on current LTS lines. Set SUME_API_KEY first; the call authenticates with the Authorization: Bearer header, one credential only.
import http from "node:http";
const base = process.env.SUME_BASE ?? "https://api.sume.com";
const key = process.env.ORDER_KEY ?? crypto.randomUUID();
function headerValueOk(value) {
if (typeof http.isValidHeaderValue === "function") return http.isValidHeaderValue(value);
try { http.validateHeaderValue("Idempotency-Key", value); return true; } catch { return false; }
}
if (!headerValueOk(key)) throw new Error("Idempotency-Key is not a legal header value");
const res = await fetch(`${base}/v1/images`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.SUME_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": key,
},
body: JSON.stringify({ model: "sume/auto", prompt: "ceramic mug on oak table", mode: "async" }),
});
console.log(res.status, key);What Sume does not do
Sume does not validate your key format beyond what HTTP allows, and the Node helper does not tell you whether a key was already used. A reused key with an edited prompt is a 409, not a fresh job. If you need to change the prompt, use a new key; if you are retrying, send the identical body. Read the full rules in the image model docs before wiring retries.
Sources
Related posts
More in Developers
- Node 26.11 ships Undici 8.11.2: tell a Sume poll timeout from an abort
Catch TimeoutError separately from AbortError when a Sume status poll in Node fetch times out, and know which Sume calls are safe to repeat after that timeout.
- Node 26 enters LTS in October 2026: pin your Sume webhook receiver
Node 26 moves to LTS this month and Node 27 Alpha starts. Pin the runtime that runs your Sume webhook receiver and prove it with a signed self-test.
- node:test mock.method on fetch: test a Sume status poll offline
Node 26 goes LTS this month. Test a Sume job status poll with node:test and mock.method on fetch: four cases, no network, no key, no third-party test library.
- npm audit signatures on @sume-com/sdk 0.2.0: what it proves, what not
Run npm audit signatures on @sume-com/sdk 0.2.0 before deploy. It checks the registry signature; the registry lists no provenance attestation for this version.
Written by Sume