Sume 401 halfway through a batch: stop every worker, do not retry

A 401 on a Sume submit means a missing, malformed or revoked key. The SDK does not retry it, and neither should you. Python sample that keeps job ids.

4 min readSume
All posts

If a batch of image submits starts getting 401 in the middle, the usual cause is a key that was revoked during a rotation. The authentication docs list 401 as a missing, malformed or revoked key and the next step as checking the header and, if necessary, creating a new key. A 403 is different: insufficient_scope means the key was created before the scope you need, and workspace_key_required means a personal key was used on a team Format.

Neither is retryable. The SDK retries only 408, 429, 5xx and transport failures, and a plain loop should follow the same rule.

Stop and keep what you have

The sample treats 401 and 403 as a stop signal and prints the job ids accepted so far. It also builds the idempotency key from the prompt with a hash, so a resumed run after the key is fixed replays instead of duplicating.

import hashlib, json, urllib.error, urllib.request

def submit_all(prompts, key):
    done = []
    for prompt in prompts:
        req = urllib.request.Request(
            "https://api.sume.com/v1/images",
            data=json.dumps({"model": "ideogram/ideogram-v4.5", "prompt": prompt,
                             "mode": "async"}).encode(),
            headers={"x-api-key": key, "content-type": "application/json",
                     "idempotency-key": "batch-" + hashlib.sha256(prompt.encode()).hexdigest()[:16]},
        )
        try:
            with urllib.request.urlopen(req, timeout=40) as res:
                done.append(json.load(res)["data"]["job"]["id"])
        except urllib.error.HTTPError as err:
            if err.code in (401, 403):  # revoked, malformed or under-scoped key
                raise SystemExit(f"stop the batch: HTTP {err.code}; jobs so far: {done}")
            raise
    return done

Status triage

Status handling from the Sume authentication and errors docs, read 2026-10-06
StatusRetry?Action
401NoStop all workers; check the key
403NoFix scope or use a workspace key
402NoAdd credits, then resume
429Yes, after retry-afterBack off; keep the same key
5xxYes, with the same keyBackoff and jitter

Recover cleanly

  • Create a new key, verify it with GET /v1/me, deploy it, then resume.
  • Jobs the server already accepted keep running; record their ids before the stop so you can poll them.
  • Skip prompts whose job ids you stored, and resubmit the rest with their original keys.
  • Revoke a key only after the replacement is live.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume