SDK waitForJob after a 202 from createImage: TypeScript sample
When createImage returns 202 on a slow gpt-image-2.5 render, pass the job id to waitForJob from @sume-com/sdk and read the terminal job instead of hand-polling.

When createImage returns status 202, read data.job.id from the envelope and pass it to waitForJob from @sume-com/sdk. It polls GET /v1/jobs/{id}/status for you, honors the server's next_poll_after_seconds, and returns the terminal job for any terminal status, not only completed. A failed job is a result you read, not an exception.
Slow settings are the likeliest to return 202: 4K, high quality, large n. Moving off a retired gpt-image-1 call to ChatGPT Image 2.5 with xhigh quality is one of them.
The sample
waitForJob throws SumeJobTimeoutError when its timeout elapses and SumeJobRequestError when a status read fails. The default timeout is generous, but set your own so a stuck job does not hold a worker.
import { createSumeClient, createImage, waitForJob } from "@sume-com/sdk";
const client = createSumeClient({ apiKey: process.env.SUME_API_KEY! });
const res = await createImage({
client,
body: {
model: "openai/gpt-image-2.5-sunburst",
prompt: "ceramic mug on linen, 4K",
quality: "xhigh",
},
});
if (res.response.status === 202) {
const env = res.data as unknown as { data: { job: { id: string } } };
const job = await waitForJob(env.data.job.id, {
client,
timeout: 300_000,
onStatus: (status) => console.log("status", status),
});
console.log(job.status);
} else {
console.log(res.data);
}Which path returns what
Read the 200 and 202 post for the same split without the SDK. The compile-time side of the migration is in the model union post.
| Situation | Response | Next step |
|---|---|---|
| Finishes inside 30 s | 200, data is an image list | Use data[].url |
| Slower than 30 s | 202, data.job.id and status_url | waitForJob(jobId) |
| mode: async or webhook | 202, same envelope | Poll or wait for the webhook |
| Terminal failure in budget | 502 | Retry or fall back |
Sources
Related posts
More in Developers
- Rotate the Sume webhook secret twice in 24 hours: the oldest one dies
One rotation keeps the old secret valid for 24 hours. A second rotation inside that window retires the secret from two rotations ago. Verifier in Python.
- Seedance 2.5 job failed: refund, new idempotency key, and rerun cost
A failed Seedance 2.5 job is refunded on Sume. Retry with a new Idempotency-Key; the old one replays the failed job. A Python handler and the rerun cost.
- Low-latency TTS without streaming: one job per sentence
Sume TTS has no streaming. To start playback early, split the script by sentence, submit the jobs in parallel and play each file as it finishes, in order.
- Shadow-run gpt-image-2.5 beside your current model before October 23
Render one prompt on a Sume image id and your current model with a separate idempotency key per model, then compare cost and output before gpt-image-1 ends.
Written by Sume