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.

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 doneStatus triage
| Status | Retry? | Action |
|---|---|---|
| 401 | No | Stop all workers; check the key |
| 403 | No | Fix scope or use a workspace key |
| 402 | No | Add credits, then resume |
| 429 | Yes, after retry-after | Back off; keep the same key |
| 5xx | Yes, with the same key | Backoff 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
- Sume 401 and 404: wrong API key, or a resource in another workspace
401 unauthorized means the API key is missing or invalid. 404 not_found means the resource does not exist in the current workspace, so check which key you used.
- Sume 402 insufficient_credits: top up, then retry the same request
A Sume 402 means the balance cannot cover the requested generation. Add funds or lower the request cost, then retry with the same Idempotency-Key.
- Sume 409 errors: job_not_completed, job_not_cancelable and more
A Sume 409 means the job operation does not fit the job's current status: job_not_completed, job_not_cancelable or job_generation_already_started.
- Sume 413 payload_too_large and 415: shrink the body, send JSON
413 means the request body is over the API limit. 415 means the body was not application/json, shown in details.received_content_type.
Written by Sume