waitForJob on a failed Sume image job: read the record, skip /result

waitForJob resolves for failed and canceled jobs instead of throwing, and /result returns 409 job_not_completed for them. How to branch on job.status.

3 min readSume
All posts

In @sume-com/sdk, waitForJob resolves with the terminal job for any terminal status, not just completed. The SDK source explains why: it reads /v1/jobs/{id} for the final hop, because GET /v1/jobs/{id}/result answers 409 job_not_completed for failed and canceled jobs, and there would be nothing to hand back.

So a failed Ideogram or gpt-image-2.5 job is a result you asked for, not an exception. Branch on job.status, exactly as a webhook handler would.

Branch on the status

import { createSumeClient, waitForJob } from "@sume-com/sdk";

const client = createSumeClient({ apiKey: process.env.SUME_API_KEY! });

export async function finish(jobId: string) {
  // Resolves for completed, failed and canceled. It throws only on timeout or a read error.
  const job = await waitForJob(jobId, { client, timeout: 5 * 60_000 });

  switch (job.status) {
    case "completed":
      return { ok: true as const, job };
    case "failed":
      return { ok: false as const, reason: job.error }; // not GET /result: that is a 409
    case "canceled":
      return { ok: false as const, reason: "canceled" };
    default:
      throw new Error(`unexpected non-terminal status ${job.status}`);
  }
}

What does throw

waitForJob behavior from the SDK source, read 2026-10-06
SituationWhat you get
completedResolved job
failed or canceledResolved job with status and error
timeout before a terminal statusSumeJobTimeoutError with jobId and lastStatus
status read fails with an API errorSumeJobRequestError with status and body

Habits that follow

  • Do not call /result on a job you have not confirmed completed; it is for finished output only.
  • On a timeout the job is still running and billable. Keep jobId and resume instead of resubmitting.
  • A failed generation is not billed, but log the error object so you can tell a bad prompt from a provider fault.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume