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.

5 min readSume
All posts

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.

Sume image job paths, per docs read 2026-10-06
SituationResponseNext step
Finishes inside 30 s200, data is an image listUse data[].url
Slower than 30 s202, data.job.id and status_urlwaitForJob(jobId)
mode: async or webhook202, same envelopePoll or wait for the webhook
Terminal failure in budget502Retry or fall back

Sources

Related posts

More in Developers

All Developers posts

Written by Sume